jquery - How to get data returned by Action after ajax form submit -
jquery - How to get data returned by Action after ajax form submit -
there partialview
httpget
method in controller. , httppost
i'm returning jsonresult
. submitting ajax form unable json info after form submit. controller code
[httpget] public partialviewresult editstudent(int id) { var getstudent = _db.student.find(id); if (getstudent != null) { homecoming partialview("editstudent", getstudent); } homecoming partialview("editstudent"); } [httppost] public jsonresult editstudent(student st) { var getdata = _db.student.find(st.id); getdata.name = st.name; getdata.class = st.class; _db.savechanges(); ilist<student> getst = _db.student.tolist(); homecoming json(getst, jsonrequestbehavior.allowget); }
this partialview page code
@using (ajax.beginform("editstudent", "home", new ajaxoptions { updatetargetid = "dv", insertionmode = insertionmode.replace, httpmethod = "post", onsuccess = "**bindst**()" })) { <div class="modal-body"> @if (model != null) { <table> <tr> <td> @html.hiddenfor(m => m.id) pupil name </td> <td>@html.textboxfor(m => m.name, new { id = "txtstname" }) </td> </tr> <tr> <td> pupil class </td> <td>@html.textboxfor(m => m.class, new { id = "txtstclass" }) </td> </tr> </table> } else { <span>@html.labelfor(m => m.id) invalid id</span> } </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal"> close</button> <input type="submit" class "btn btn-primary" value="submit" /> </div> }
as can see want phone call bindst() function written in js.
this bindst function
function bindst(data) { var tblhtml = ''; $.each(data, function (i, d) { tblhtml += "<tr><td>" + d.id + "</td><td>" + d.name + "</td><td>" + d.class + "</td><td><img src='../../images/edit.jpg' style='width:25px;cursor:pointer;height:25px;' class='dvedit'/> <img src='../../images/delete.png' style='width:25px;cursor:pointer;height:25px;' class='dvdelete' /></td></tr>"; }); $('#tblst').find('tbody').html(tblhtml); }
but bindst function need paramter info . , action editstudent returning json want pass in . how can info can pass in function.
jquery asp.net ajax asp.net-mvc json
Comments
Post a Comment