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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -