c# - How to get all route-values after {controller}/{method} -
i render buttons in order change language following:
<%: html.actionlink( "en", viewcontext.routedata.values["action"].tostring(), new { lang = "en" }, new { @class="tab" })%>
this render me link follows: {...}\en\mycontroller\mymethod
- problem left lose routing values, follow after method's name. how possible add them well?
thanks tips!
i use few handy extension methods:
public static routevaluedictionary toroutevaluedictionary(this namevaluecollection collection) { routevaluedictionary dic = new routevaluedictionary(); foreach (string key in collection.keys) dic.add(key, collection[key]); return dic; } public static routevaluedictionary addorupdate(this routevaluedictionary dictionary, string key, object value) { dictionary[key] = value; return dictionary; } public static routevaluedictionary removekeys(this routevaluedictionary dictionary, params string[] keys) { foreach (string key in keys) dictionary.remove(key); return dictionary; }
this allows me following:
//update current routevalues , pass values. @html.actionlink("en", viewcontext.routedata.values["action"], viewcontext.routedata.values.addorupdate("lang", "en")) //grab querystring, update value, , set routevalues. @html.actionlink("en", viewcontext.routedata.values["action"], request.querystring.toroutevaluedictionary.addorupdate("lang", "en"))
Comments
Post a Comment