asp.net - Change culture of site that is based on link -
i have asp.net 5 website culture defined in link. example:
http://localhost:8080/nl/customers
http://localhost:8080/fr/customers
http://localhost:8080/en/customers
i need implement button change language. there way without having parse url , adding language prefix myself?
you can create helper method
public static class urlhelperextensions { public static string routetocurrent(this urlhelper urlhelper, routedata routedata, object routevalues) { // create idictionary<string, object> var requestroutedata = new routevaluedictionary(routedata.values); var replacevalues = new routevaluedictionary(routevalues); foreach (var value in replacevalues) { if (requestroutedata.containskey(value.key)) { requestroutedata[value.key] = value.value; } else { requestroutedata.add(value.key, value.value); } } return urlhelper.routeurl(requestroutedata); } }
as parameters pass current routedata , anonymous object keys , values want change.
@foreach (var lang in model.languagelist) { <li> <a href="@url.routetocurrent(viewcontext.routedata, new {locale = lang})">@lang</a> </li> }
Comments
Post a Comment