Reputation: 13773
I am displaying and determining the selected language in my website by using URLs in this format :
/{languageCode}/Area/Controller/Action
And in my C# when I need to find the language Code I am using this syntax :
RouteData.Values["languageCode"]
However, when I need to call an action using JQuery, how do I determine the language code so that I can call the correct route i.e. en-US/Area/Controller/Action
? I don't know how to access this information in my client side Javascript. Can anybody help?
Upvotes: 2
Views: 832
Reputation: 7200
You could emit it, server-side, e.g.:
var url = '@Url.Action("Action", routeValues)';
Upvotes: 0
Reputation: 19465
Since your URL has the language code. How about using
window.location
https://developer.mozilla.org/en/DOM/window.location
And then extract the language from the url. Maybe something like:
var url = "example.com/en-us/Area/Controller/Action"; //or window.location:
var lang = url.split("/")[1];
No need to use JQuery! :)
Upvotes: 1