asp.net mvc - Errors when passing data via jquery ajax -
i have pretty simple ajax request i'm sending on server in order data , fill edit modal. reason keeps returning error , can't figure out why. i've debugged server side, parameter comes in correctly , data found , returned, still error though.
here's code might see missing here.
request:
function editnorm(id) { $.ajax({ type: "post", url: "@url.action("getnormviewmodel")", datatype: 'json', contenttype: 'application/json; charset=utf-8', data: json.stringify({id : id}), cache: false, success: function(data) { fillformforediting(data.nvm); }, error: function() { alert("error on editnorm function"); } }); }
server side:
public jsonresult getnormviewmodel(int id) { var nvm = new normviewmodel {norm = db.norms.find(id), materials = db.materials.tolist()}; return json(new {nvm = nvm}, jsonrequestbehavior.allowget); }
firstly: using post method on javascript while controller accepts get, add action:
[httppost] public jsonresult getnormviewmodel(int id) { return json(new { ... }); }
secondly: db
linqtosql / entity framework context? if so, make sure no call data context performed after data returned. (i.e. changed action , return return json(new { nvm = "test" });
, console.log/alert
make sure you've got result back. tells model failed when it's returned due late binding.
Comments
Post a Comment