开发者

How to change the url according to the combobox value in mvc3?

开发者 https://www.devze.com 2023-04-05 01:10 出处:网络
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.

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();
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号