How to add querystring values ​​using RedirectToAction method?

In asp.net mvc, I use this code:

RedirectToAction("myActionName"); 

I want to pass some values ​​through the query string, how to do this?

+55
c # asp.net-mvc url-redirection
Jul 01 '09 at 3:52
source share
3 answers

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

+111
Jul 01 '09 at 3:57
source share

Also consider using T4MVC, which has the extension methods AddRouteValue() and AddRouteValues() (see here ).

+3
Jan 10 '13 at 20:16
source share

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 .

QueryString keys cannot begin with numbers. Changing from 404 to FileNotFound solved my problem, i.e. mysite.com?FileNotFound=nonExistentFile.txt .

+1
Nov 15 '16 at 21:07
source share



All Articles