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?
Asked
Active
Viewed 74 times
2
-
Can you share the target action signature? Is it one from Uri and one from body? – Athanasios Kataras Jan 17 '20 at 16:35
-
Possible duplicate of https://stackoverflow.com/questions/15385442/passing-data-between-different-controller-action-methods – camainc Jan 17 '20 at 16:48
2 Answers
3
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"
});

Athanasios Kataras
- 25,191
- 4
- 32
- 61
-
Thank you so much for help .my actual requirements was this to passing multiple variables using RedirectToAction. It is working fine. – Kaushal Jan 18 '20 at 03:56
-
1
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

camainc
- 3,750
- 7
- 35
- 46