在asp.net mvc中,我使用了以下代码:
RedirectToAction("myActionName");
我想通过查询字符串传递一些值,我该怎么做呢?
发布于 2009-07-01 03:57:31
传递的任何不属于路由的值都将用作查询字符串参数:
return this.RedirectToAction
("myActionName", new { value1 = "queryStringValue1" });
将返回:
/controller/myActionName?value1=queryStringValue1
假设没有名为"value1“的路由参数。
发布于 2020-04-03 20:33:01
对于像我这样希望将当前查询字符串值添加到RedirectToAction中的人,以下是解决方案:
var routeValuesDictionary = new RouteValueDictionary();
Request.QueryString.AllKeys.ForEach(key => routeValuesDictionary.Add(key, Request.QueryString[key]));
routeValuesDictionary.Add("AnotherFixedParm", "true");
RedirectToAction("ActionName", "Controller", routeValuesDictionary);
如您所见,解决方案是使用RouteValueDictionary对象
发布于 2013-01-11 04:16:51
还可以考虑使用T4MVC,它具有扩展方法AddRouteValue()
和AddRouteValues()
(如setting query string in redirecttoaction上的这个问题所示)。
https://stackoverflow.com/questions/1067200
复制相似问题