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);
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());
Is there an other better way ?
Thx
question from:
https://stackoverflow.com/questions/5818065/how-to-pass-request-querystring-to-url-action 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…