7

这是我的代码

 <div id="pro_pag2">
 @using (Html.BeginForm("Product", "Main", new { customerId = mdlLoginData.CustomerID,   GroupID = ViewBag.GroupID, page = 1 }, FormMethod.Post, new { }))
                    {
                        @Html.DropDownList("PageSize", new SelectList(new   Dictionary<string, string> {{ "18", "18" }, { "12", "12" },{ "6", "6" }  }, "Key", "Value"), new { @class = "pro_pag_tf1" })
                    }
</div>

我的问题是如何在下拉列表的选择更改时提交表单

4

1 回答 1

17

您可以使用 jQuery。给下拉列表一个id,就像这样。

 <div id="pro_pag2">
 @using (Html.BeginForm("Product", "Main", new { customerId = mdlLoginData.CustomerID,   GroupID = ViewBag.GroupID, page = 1 }, FormMethod.Post, new { }))
      {
           @Html.DropDownList("PageSize", 
                new SelectList(new Dictionary<string, string> {...}, "Key", "Value"), 
                new { @class = "pro_pag_tf1", id = "pagesizelist" })
      }
 </div>

然后使用 jQuery 提交其父表单

$('#pagesizelist').on('change', function(event){
    var form = $(event.target).parents('form');

    form.submit();
});
于 2013-09-11T16:21:18.137 回答