Jquery.ajax POST call running wrong method supplied -
i trying run action method jquery.ajax call seeing controller name post method "edit" being run instead of action supplying in url attribute "deleteitem"
client
$.ajax({ type: 'post', url: '/edit/deleteitem?id=1', contenttype: 'application/json', success: function () { alert('deleted ok'); }, error: function (xhr, ajaxoptions, thrownerror) { alert(thrownerror); }, });
server code
// expect running [httppost] public actionresult deleteitem(string id) { return json(""); } // , not [httppost] [authorize] [validateinput(false)] public actionresult edit(viewmodel) { try ....
route config
routes.maproute( "edit", // route name "edit/{id}", // url parameters new { controller = "edit", action = "edit", id = urlparameter.optional });
is there have done wrong in jquery.ajax method?
thanks
given route config posted, routes go edit
action. need make action configurable per url. try this:
routes.maproute( "edit", // route name "edit/{action}/{id}", // url parameters new { controller = "edit", action = "edit", id = urlparameter.optional });
your actions available at:
// edit: http://localhost:63672/edit/edit // delete: http://localhost:63672/edit/deleteitem
Comments
Post a Comment