Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

submit form at dropdown change event in mvc4

here is my code

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

my question is that how do I submit form at selection change of the dropdown

like image 864
ali Avatar asked Sep 11 '13 16:09

ali


1 Answers

You can use jQuery. Give the drop down list an id, like so.

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

Then use jQuery to submit its parent form

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

    form.submit();
});
like image 117
nforss Avatar answered Sep 28 '22 00:09

nforss