how to add querystring values with RedirectToAction method?

mrblah picture mrblah · Jul 1, 2009 · Viewed 65k times · Source

In asp.net mvc, I am using this code:

RedirectToAction("myActionName");

I want to pass some values via the querystring, how do I do that?

Answer

Talljoe picture Talljoe · Jul 1, 2009

Any values that are passed that aren't part of the route will be used as querystring parameters:

return this.RedirectToAction
  ("myActionName", new { value1 = "queryStringValue1" });

Would return:

/controller/myActionName?value1=queryStringValue1

Assuming there's no route parameter named "value1".