在mvc4中的下拉更改活动中提交表单

时间:2013-09-11 16:07:14

标签: asp.net-mvc asp.net-mvc-4

这是我的代码

 <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>

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

1 个答案:

答案 0 :(得分:14)

您可以使用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();
});