In asp.net mvc, I use this code:
RedirectToAction("myActionName");
I want to pass some values through the query string, how to do this?
Any transmitted values that are not part of the route will be used as request parameters:
return this.RedirectToAction ("myActionName", new { value1 = "queryStringValue1" });
Will return:
/controller/myActionName?value1=queryStringValue1
Assuming there is no route parameter named "value1".
Also consider using T4MVC, which has the extension methods AddRouteValue() and AddRouteValues() (see here ).
AddRouteValue()
AddRouteValues()
Do not make the same mistake that I made. I handled 404 errors and wanted to redirect using 404=filename in querystring, i.e. mysite.com?404=nonExistentFile.txt .
404=filename
mysite.com?404=nonExistentFile.txt
QueryString keys cannot begin with numbers. Changing from 404 to FileNotFound solved my problem, i.e. mysite.com?FileNotFound=nonExistentFile.txt .
404
FileNotFound
mysite.com?FileNotFound=nonExistentFile.txt