MVC信息:System.Web.HttpException:公共行动方法“删除”并没有在控制器发现 [英] MVC: System.Web.HttpException: A public action method 'Delete' was not found on controller

查看:182
本文介绍了MVC信息:System.Web.HttpException:公共行动方法“删除”并没有在控制器发现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的控制器上调用删除方法的HTML辅助方法。

 公共静态MvcHtmlString DeleteEmployeeOtherLeave(这个HTML的HtmlHelper,串LINKTEXT,离开_leave)
{
    返回html.RouteLink(LINKTEXT,默认,
        新{_employeeOtherLeaveId = _leave.LeaveId,行动=删除},
        新{的onclick =$。员额(this.href);返回false; });
}

在我的控制器我有;

 的[AcceptVerbs(HttpVerbs.Delete)
公众的ActionResult删除(INT _employeeOtherLeaveId)
{
    EmployeeOtherLeaf.Delete(_employeeOtherLeaveId);    返回RedirectToAction(工资);
}

不过,我得到这个运行时错误消息;

  System.Web.HttpException:公共行动方法删除并没有在控制器发现


解决方案

这有可能是你的行动没有被通过发送正确的删除动词在这种情况下,一个HTTP请求调用。尝试更新AcceptVerbs属性采取POST来代替。

I have a Html helper method that calls a Delete method on my controller.

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;" });
}

On my controller I have;

[AcceptVerbs(HttpVerbs.Delete)]
public ActionResult Delete(int _employeeOtherLeaveId)
{
    EmployeeOtherLeaf.Delete(_employeeOtherLeaveId);

    return RedirectToAction("Payroll");
}

But I get this runtime error message;

    System.Web.HttpException: A public action method 'Delete' was not found on controller

解决方案

It's possible that your action isn't being invoked by an HTTP request that is sending the correct "DELETE" verb in this case. Try updating your AcceptVerbs attribute to take a POST instead.

这篇关于MVC信息:System.Web.HttpException:公共行动方法“删除”并没有在控制器发现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆