Kaushal
Kaushal

Reputation: 31

Passing values using RedirectToAction Method

I want to pass two variables from one action method to another action method using RedirectToAction. i am able to send one variable or one object at a time. Is it possible to send two or more values at a time?

Upvotes: 2

Views: 85

Answers (2)

camainc
camainc

Reputation: 3810

Put the values into the TempData dictionary.

TempData["ValueOne"] = "SomeValue"
TempData["ValueTwo"] = "SomeOtherValue"

In the second method after the redirect, get the values out of TempData:

var val1 = TempData["ValueOne"]; 
var val2 = TempData["ValueTwo"]; 

Here is a link to the docs on the TempData dictionary:

https://learn.microsoft.com/en-us/dotnet/api/system.web.mvc.tempdatadictionary?view=aspnet-mvc-5.2

Upvotes: 1

Athanasios Kataras
Athanasios Kataras

Reputation: 26352

I'm assuming you are taking about a GET request with multiple query parameters on the URL.

return RedirectToAction("action", "controller", new {
           id = 1,
           searchParamOne = "value", 
           anotherParam = "value2" 
       });

Upvotes: 3

Related Questions