2

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?

Kaushal
  • 31
  • 2

2 Answers2

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
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