How to change the url according to the combobox value in mvc3?
When I change the page path, like this: localhost/XXX/fr - the page is in french and when I write: localhost/XXX/en - the page is in english. (the text is taken from the resources files).
I also have a combobox contains "english" with value=en and "french" with value="fr".
now, How do I get the URL change by the selected value? I was thinking that maybe i sould write something like-
controllerName/.../theSelectedValue
but I dont know how to do this.
(the value selected is = $("#combobox")[0].value
in JQuery, Can I write it in JQuery?)
I actualy did this:
var urlString = window.location.host; //the url with localhost:XXX only -and if it changes it will adjust i开发者_Python百科tself
var Lang = $(this)[0].value; //en or fr
window.location = "http://" + urlString + "/" + Lang;
but now I have another problem: window.location - refreshes the page, and the $(this)[0].value - returns to be as the beginning. for example if I change the combobox from "english" to "french", the language does change to french (coz the url isnt refreshed), but in the combobox, the selected field is "english" again and I cant change it because all the page is refreshed. so...is anybody can tell me what to do??
thank in advance.
You can attach to the .change event for the combobox, like this:
$('#CLIENT_ID_FOR_YOUR_CHECKBOX_HERE').change(function() {
window.location = "http://localhost/XXX/" + $(this).val();
});
精彩评论