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?
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?
Any values that are passed that aren't part of the route will be used as querystring parameters:
Would return:
Assuming there's no route parameter named "value1".
Also consider using T4MVC, which has the extension methods
AddRouteValue()
andAddRouteValues()
(as seen on this question on setting query string in redirecttoaction).Do not make the same mistake I was making. I was handling 404 errors and wanted to redirect with
404=filename
in the querystring, i.e.mysite.com?404=nonExistentFile.txt
.QueryString Keys cannot begin with numbers. Changing from
404
toFileNotFound
solved my issue, i.e.mysite.com?FileNotFound=nonExistentFile.txt
.