Friday, March 19, 2010

Jquery with ASP.NET mvc: How to call an action method when selected item changed in a drop down list

In your View page imagine you have a dropdown list like this.

<%= Html.DropDownList("drop_down_list_id", (System.Collections.Generic.List)(ViewData["Names"] == null ? "" : ViewData["Names"]), new { @class = "smallDropdownList" })%>


Following is the jquery function which calls the mentioned controller's action method when dropdown list's selected item changed.

<script type="text/javascript">

$(document).ready(function() {

$("#drop_down_list_id").change(function () {

this.form.action = "/ControllerName/ActionName";
this.form.submit();

});

});
</script>

0 comments:

Post a Comment