javascript - C#/Asp.net Post Function Not Working -
okay, here code:
var functionaddword = function () { var dictionaryitem = { }; dictionaryitem.word = $('#newwordid').val().trim(); dictionaryitem.definition = $('#newdefinition').val().trim(); $.post("/word/", dictionaryitem, function (result) { window.alert(result.word); }); }; web api:
config.routes.maphttproute( name: "add or edit word", routetemplate: "word", defaults: new { controller = "values", action = "post"} ); controller:
[httppost] public jsonresult<dictionaryitem> post([frombody] dictionaryitem word ) { var dictionaryrepository = new dictionaryrepository(); dictionaryrepository.addoreditword(word); var response = new dictionaryitem { word = word.word, definition = word.definition}; return json(response); } i have button calls functionaddwork, work. dictionaryitem set properly, have tested well. $.post not call controller method properly, , can't find controller. been working on 2+ hours , can't figure out missing.
thank in advance, jay
Comments
Post a Comment