2

我正在尝试通过 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");
}

我错过了什么?

4

3 回答 3

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."); }
});
于 2013-01-17T00:29:29.293 回答
0

检查您的操作的 URL 模板还检查需要为字符串的方法原型

于 2013-01-17T06:09:22.903 回答
0

原来我的网站不接受 DELETE 动词。删除了 WebDAVModule 并开始工作。现在,关于 AuthToken 的下一个问题。

<system.webServer>
<modules>
<remove name="WebDAVModule" />
...
于 2013-01-22T20:00:09.707 回答