javascript - Unable to pass data from jQuery ajax to Api Controller -
i don't know went wrong - using fiddler when pass data controller string able receive data throw ajax unable data - please
$("#rollnumber").change(function () { var data = $.trim($(this).val()); $.ajax({ method: "post", url: "api/home/postdetails", data: { rollnumber: data }, datatype: "json", contenttype: "application/json", success: function (data) { $("#firstname").val(data.firstname); $("#lastname").val(data.lastname); } }) }); [httppost] public httpresponsemessage postdetails([frombody] string rollnumber) { try { if(rollnumber != null) { businesslogic business = new businesslogic(); modelclass model = business.getstudent(convert.toint32(rollnumber)); return request.createresponse(httpstatuscode.ok, model); } return request.createresponse(httpstatuscode.notfound, "there no user in specfic roll number " + rollnumber); } catch(exception ex) { return request.createerrorresponse(httpstatuscode.badrequest, ex); } }
you can try this:
remove frombody method.
Comments
Post a Comment