Я на самом деле использую несколько удобных методов расширения:
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;
}
Это позволяет мне сделать следующее:
//Update the current routevalues and pass it as the values.
@Html.ActionLink("EN", ViewContext.RouteData.Values["action"], ViewContext.RouteData.Values.AddOrUpdate("lang", "en"))
//Grab the querystring, update a value, and set it as routevalues.
@Html.ActionLink("EN", ViewContext.RouteData.Values["action"], Request.QueryString.ToRouteValueDictionary.AddOrUpdate("lang", "en"))