如何根据mvc3中的组合框值更改URL?

时间:2011-09-14 14:37:11

标签: jquery asp.net-mvc asp.net-mvc-3 combobox routing

当我更改页面路径时,如下所示:  localhost / XXX / fr - 该页面是法语 当我写:  localhost / XXX / en - 该页面是英文的。  (文本来自资源文件)。

我还有一个组合框包含“english”,其值为value = en  和“法语”,价值=“fr”。

现在,如何通过所选值获取URL更改?  我在想,也许我会写一些像 -

controllerName/.../theSelectedValue

但我不知道该怎么做。

(在JQuery中选择的值是= $("#combobox")[0].value,我可以在JQuery中编写吗?)


我实际上是这样做的:

var urlString = window.location.host;   //the url with localhost:XXX only -and if it changes it will adjust itself 

var Lang = $(this)[0].value;            //en or fr
window.location = "http://" + urlString + "/" + Lang;

但现在我有另一个问题:window.location - 刷新页面,$(this)[0] .value - 返回作为开头。例如,如果我将组合框从“英语”更改为“法语”,语言确实会更改为法语(因为网址没有刷新),但在组合框中,所选字段再次为“英语”而我无法更改它因为所有页面刷新。 所以...有人可以告诉我该怎么做??

提前谢谢。

1 个答案:

答案 0 :(得分:1)

您可以附加到组合框的.change事件,如下所示:

$('#CLIENT_ID_FOR_YOUR_CHECKBOX_HERE').change(function() {
  window.location = "http://localhost/XXX/" + $(this).val();
});
相关问题