Reputation: 31
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
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
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