我有一个Html助手方法,它在我的控制器上调用Delete方法。
public static MvcHtmlString DeleteEmployeeOtherLeave(this HtmlHelper html, string linkText, Leave _leave)
{
return html.RouteLink(linkText, "Default",
new { _employeeOtherLeaveId = _leave.LeaveId, action = "Delete" },
new { onclick = "$.post(this.href); return false;" });
}在我的控制器上我有;
[AcceptVerbs(HttpVerbs.Delete)]
public ActionResult Delete(int _employeeOtherLeaveId)
{
EmployeeOtherLeaf.Delete(_employeeOtherLeaveId);
return RedirectToAction("Payroll");
}但是我得到了这个运行时错误信息;
System.Web.HttpException: A public action method 'Delete' was not found on controller发布于 2011-02-05 00:54:10
在这种情况下,发送正确的"DELETE“动词的HTTP请求可能不会调用您的操作。尝试更新您的AcceptVerbs属性以获取帖子。
发布于 2011-02-05 00:53:32
您正在发送POST请求,而您的控制器操作需要DELETE谓词。所以:
public static MvcHtmlString DeleteEmployeeOtherLeave(this HtmlHelper html, string linkText, Leave _leave)
{
return html.RouteLink(linkText, "Default",
new { _employeeOtherLeaveId = _leave.LeaveId, action = "Delete" },
new { onclick = "$.ajax({url: this.href, type: 'DELETE'}); return false;" });
}发布于 2011-02-07 13:21:58
或者,您也可以更改表单方法属性中的谓词,以删除这两种方法中的任何一种
https://stackoverflow.com/questions/4900615
复制相似问题