提供了运行错误方法的Jquery.ajax POST调用
我试图从jQuery.ajax调用中运行一个操作方法,但我看到的是正在运行控制器名称POST方法“Edit”,而不是我在url属性“DeleteItem”中提供的操作 客户提供了运行错误方法的Jquery.ajax POST调用,jquery,ajax,asp.net-mvc,post,Jquery,Ajax,Asp.net Mvc,Post,我试图从jQuery.ajax调用中运行一个操作方法,但我看到的是正在运行控制器名称POST方法“Edit”,而不是我在url属性“DeleteItem”中提供的操作 客户 $.ajax({ type: 'POST', url: '/Edit/DeleteItem?id=1', contentType: 'application/json', success: function () { alert('De
$.ajax({
type: 'POST',
url: '/Edit/DeleteItem?id=1',
contentType: 'application/json',
success: function () {
alert('Deleted OK');
},
error: function (xhr, ajaxOptions, thrownError) {
alert(thrownError);
},
});
服务器代码
// I expect it to be running this
[HttpPost]
public ActionResult DeleteItem(string id)
{
return Json("");
}
// And not this
[HttpPost]
[Authorize]
[ValidateInput(false)]
public ActionResult Edit(ViewModel)
{
try
....
路由配置
routes.MapRoute(
"Edit", // Route name
"Edit/{id}", // URL with parameters
new { controller = "Edit", action = "Edit", id = UrlParameter.Optional });
在JQuery.ajax方法中,我有没有做错什么
谢谢鉴于您发布的路线配置,您的所有路线都将转到
编辑
操作。您需要根据URL配置操作。试试这个:
routes.MapRoute(
"Edit", // Route name
"Edit/{action}/{id}", // URL with parameters
new { controller = "Edit", action = "Edit", id = UrlParameter.Optional });
您的操作将在以下位置提供:
// Edit:
http://localhost:63672/Edit/Edit
// Delete:
http://localhost:63672/Edit/DeleteItem
谢谢,当你提到上面的路由时,它点击了。让我这样做时会标记为正确吗