DropDownListFor自动回发

时间:2013-07-10 00:05:34

标签: asp.net-mvc jquery html.dropdownlistfor

如何在MVC中为DropDownListFor实现类似自动回发的功能。目前,在下拉列表中选择一个值后,我必须刷新页面以查看应用于页面的更改。

在视图中,

dropdownlistfor就像

@Html.DropDownListFor(m => m.SelectedItem, Model.MyItemList, new { @id = "DropDownListForId"})

并且onchange事件按原样处理

<script type = "text/javascript">
$(function () {
    $('#DropDownListForId').change(function () {
        var item = $(this).val();
        $.ajax({
            url: '@Url.Action("SomeAction", "SomeController")',
            type: 'GET',
            data: { value: item },
            success: function(result) {

            }
        });
    });
});
</script>

谢谢!

1 个答案:

答案 0 :(得分:1)

我认为您可以通过在DropDownList

的更改事件上提交表单来实现此目的

假设myForm形成id

<script type = "text/javascript">
$(function () {
    $('#DropDownListForId').change(function () {
        $('form#myForm').submit();
    });
});
</script>