MVC3 DDL 自动回发选择类似



我知道MVC没有autoposback功能,这需要使用JS/JQuery来完成,这就是我的问题开始的时候......还不知道该怎么做。

这是我填充 ddl 的方式:

@Html.DropDownListFor(x => x.CurrentCountry,
                  new SelectList(Model.Countries.ToList(), "Code", "Name"))

我的网址格式如下:

localhost/Products/?country=US&currency=USD&category=17&page=2

如何添加回发功能以采用所选国家/地区?

谢谢。

我知道MVC没有autoposback功能,这需要使用JS/JQuery来完成

没必要。您可以将下拉列表放在 HTML <form>中,当用户提交此表单时,所选值将发送到服务器。

另一方面,如果要在用户更改选择时传输所选值,则需要使用 javascript 并订阅 onchange 事件。例如,如果你使用 jQuery:

$(function() {
    // subscribe to the change event of the dropdown
    $('#CurrentCountry').change(function() {
        // find the containing form and submit it
        $(this).closest('form').submit();
    });
});

最新更新