我正在尝试通过Ajax执行DELETE(首选)或POST。
$(document).ready(function () {
$("a.deleteOne").click(function () {
var id = $(this).parents('td:first').children('.hiddenId').val();
var title = $(this).parents('tr:first').children('td:first').text();
if (confirm("Really delete the [" + title + "] document?")) {
$.ajax({
type: "POST",
url: "/WebApp/Area/Documents/Delete/" + id,
//data: { id: id },
success: function () { alert("Document [" + title + "] deleted."); },
failure: function () { alert("Document [" + title + "] was NOT deleted."); }
});
}
});
return false;
});
由于某种原因,控制器的动作没有被调用。
Action code looks like:
[ValidateAntiForgeryToken]
[Transaction]
[AcceptVerbs(HttpVerbs.Post)]
//[AcceptVerbs(HttpVerbs.Delete)]
public ActionResult Delete(int id)
{
if (!BaseAuthorizationProvider.HasPermissionToPerform(App.Core.Security.Operations.CreateDocumentTask))
{
HandlePermissionException();
}
ActionConfirmation deleteConfirmation = DocumentManagementService.Delete(id);
TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = deleteConfirmation.Message;
return RedirectToAction("Index");
}
我错过了什么?
答案 0 :(得分:1)
试试这个,略有不同,我猜你正在使用区域,只需替换YourController和YourArea。
$.ajax({
type: "POST",
url: '@Url.Action("Delete", "YourController", new { area = "YourArea" })',
data: { id: id },
success: function () { alert("Document [" + title + "] deleted."); },
error: function () { alert("Document [" + title + "] was NOT deleted."); }
});
答案 1 :(得分:0)
检查您的操作的网址模板 还要检查需要为String
的方法原型答案 2 :(得分:0)
原来我的网站不接受DELETE动词。删除了WebDAVModule,它开始工作。现在,关于AuthToken的下一个问题。
<system.webServer>
<modules>
<remove name="WebDAVModule" />
...