在asp.net mvc的设置查询字符串redirecttoaction [英] setting query string in redirecttoaction in asp.net mvc
问题描述
我必须做在asp.net mvc的视图 redirecttoaction
调用具有不同参数,可以从视图(网格的状态)的引用页提取。
我(在隐藏字段)查询字符串的内容(有时是空的,有时2个参数等),所以我有问题,创建路由值数组。
是否有一些助手,这帮助我转换查询字符串路由值数组?
是这样的:
字符串查询字符串=sortdir = ASC&放大器; PAG = 5;
返回RedirectToAction(指数,ConvertToRouteArray(查询字符串));
要创建一个通用的解决方案您的查询字符串转换为字典和词典的RouteValueDictionary。
VAR分析= HttpUtility.ParseQueryString(TEMP);
字典<字符串对象> querystringDic = parsed.AllKeys
.ToDictionary(K => K,K =>(对象)解析[K]);返回RedirectToAction(指数,新RouteValueDictionary(querystringDic));
I have to do a redirecttoaction
call in asp.net mvc view with varying params, extracted from the referrer page of the view (the status of a grid).
I have (in an hidden field) the content of the query string (sometimes empty, sometimes with 2 parameters and so on), so I have problems to create the route values array.
Are there some helpers, that help me to convert a query string a route values array? Something like:
string querystring ="sortdir=asc&pag=5";
return RedirectToAction( "Index", ConvertToRouteArray(querystring));
To create a generic solution convert your querystring to a Dictionary and at the dictionary to the RouteValueDictionary.
var parsed = HttpUtility.ParseQueryString(temp);
Dictionary<string,object> querystringDic = parsed.AllKeys
.ToDictionary(k => k, k => (object)parsed[k]);
return RedirectToAction("Index", new RouteValueDictionary(querystringDic));
这篇关于在asp.net mvc的设置查询字符串redirecttoaction的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!