怎样的Request.QueryString传递给Url.Action? [英] How to pass Request.QueryString to Url.Action?
本文介绍了怎样的Request.QueryString传递给Url.Action?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的方法建立一个网址:
I'm building an url using the method:
Url.Action("action", "controller");
我想通过查询字符串当前请求到该网址为好。
类似如下(但它不工作):
I like to pass the querystring for the current request into that url as well. Something like the following (but it doesn't work):
Url.Action("action", "controller", Request.QueryString);
查询字符串转换为routevalues可能有以下扩展名:
Converting the QueryString to routevalues is possible with the following extension:
public static RouteValueDictionary ToRouteValues(this NameValueCollection queryString)
{
if (queryString.IsNull() || queryString.HasKeys() == false) return new RouteValueDictionary();
var routeValues = new RouteValueDictionary();
foreach (string key in queryString.AllKeys)
routeValues.Add(key, queryString[key]);
return routeValues;
}
通过扩展方式下不工作:
With the extension method the following does work:
Url.Action("action", "controller", Request.QueryString.ToRouteValues());
是否有其他更好的办法?
THX
Is there an other better way ? Thx
推荐答案
扩展方法似乎是正确的,是要走的路。
The extension method seems correct and is the way to go.
这篇关于怎样的Request.QueryString传递给Url.Action?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文