我有一个 Html 辅助方法,它在我的 Controller 上调用 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;" });
}
在我的 Controller 上;
[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
最佳答案
在这种情况下,发送正确“DELETE”动词的 HTTP 请求可能未调用您的操作。尝试更新您的 AcceptVerbs 属性以改为采用 POST。
关于asp.net-mvc - MVC : System. Web.HttpException:在 Controller 上找不到公共(public)操作方法 'Delete',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4900615/