How to write ajax function in c# -
the below function how write in c# backend. post method via list.
$(function () { $.ajax({ type: "post", url: "default.aspx/getcustomers", data: '{}', contenttype: "application/json; charset=utf-8", datatype: "json", success: onsuccess, failure: function (response) { alert(response.d); }, error: function (response) { alert(response.d); } }); });
you should have customer model in backend, can try this:
[httppost] public string getcustomers() { list<customers> listcustomers = new list<customers>(); /* list of customers returned database or picking data*/ customersviewmodel model = new customersviewmodel(){ customers = listcustomers; } return json(model, jsonrequestbehavior.allowget); }
Comments
Post a Comment