在asp.net的MVC,我使用这个代码:
RedirectToAction("myActionName");
我想通过查询字符串传递一些值,我该怎么做呢?
在asp.net的MVC,我使用这个代码:
RedirectToAction("myActionName");
我想通过查询字符串传递一些值,我该怎么做呢?
所传递不属于路线的一部分的任何值将被用作查询字符串参数:
return this.RedirectToAction
("myActionName", new { value1 = "queryStringValue1" });
将返回:
/controller/myActionName?value1=queryStringValue1
假设有一个名为“VALUE1”无路由参数。
也可以考虑使用T4MVC ,它具有扩展方法AddRouteValue()
和AddRouteValues()
作为上看到关于这个问题的redirecttoaction设置查询字符串 )。
不要让我犯同样的错误。 我正在处理404错误,并希望与重定向404=filename
中的查询字符串,即mysite.com?404=nonExistentFile.txt
。
查询字符串键不能以数字开头。 改变从404
到FileNotFound
解决了我的问题,即mysite.com?FileNotFound=nonExistentFile.txt
。