javascript - MVC DropDownList selection changed not firing Ajax -
i new mvc , have been doing lots of looking, can't figure out why isn't working.
i have following view code:
$(function() { $("#ddlnumberofrecords").change(function() { var numberofrecords = $("#ddlnumberofrecords").val(); $.ajax({ type: "post", url: '@url.action("numberofrecordschanged")', data: { numberofrecords: numberofrecords }, success: function(returndata) { if (!returndata.ok) { window.alert(' error : ' + returndata.message); } else { $('#grid').html(returndata); } } }); }); }); @html.dropdownlist("ddlnumberofrecords", model.numberofrecordsselectlist)
can tell me wrong that? also, there way debug javascript? put breakpoints on there, never load.
edit: action. there no real content yet because trying work @ point. have breakpoint , never gets hit.
[httppost] public actionresult numberofrecordschanged(int numberofrecords) { return null; }
with shown code works 100%. made mock prove that.
controller
public actionresult index() { viewmodel model = new viewmodel { numberofrecordsselectlist = new list<selectlistitem> { new selectlistitem { selected = false, text = "one", value = "1", }, new selectlistitem { selected = false, text = "two", value = "2", }, } }; return view(model); } [httppost] public actionresult numberofrecordschanged(int numberofrecords) { return null; }
view
@model mvcapplication1.models.viewmodel <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript"> $(function() { $("#ddlnumberofrecords").change(function() { var numberofrecords = $("#ddlnumberofrecords").val(); $.ajax({ type: "post", url: '@url.action("numberofrecordschanged")', data: { numberofrecords: numberofrecords }, success: function (returndata) { //no return data proviced //if (!returndata.ok) { // window.alert(' error : ' + returndata.message); //} else { // $('#grid').html(returndata); //} } }); }); }); </script> @html.dropdownlist("ddlnumberofrecords", model.numberofrecordsselectlist)
if getting error please share how creating list items, error is, , other details relevant problem. thanks.
Comments
Post a Comment