调用控制器动作MVC5

时间:2014-10-01 08:19:49

标签: c# asp.net asp.net-mvc-3 asp.net-mvc-5

好的,所以我得到了控制器中的动作,代码是:

[HttpPost]
public ActionResult SaveRow(int? id)
{
    //some db operations.
    return RedirectToAction("Index");
}

并且在视野中我得到了

@Html.ActionLink(Translation.Accept, "SaveRow", new { id = item.New.RecId })

当我点击按钮可以运行此操作而不重定向到url /SaveRow/时,我收到错误404? 也许这个按钮使用错误我是mvc5中的新手,所以请耐心等待。

1 个答案:

答案 0 :(得分:5)

记录在案here: -

  

2.指向动作的超链接或锚标记将始终是HttpGet。

尝试下面放置GET的代码,因为默认情况下需要[HttpGet],因此请删除[HttpPost]属性

[HttpGet]
public ActionResult SaveRow(int? id)
{
    //some db operations.
    return RedirectToAction("Index");
}

作为MVC的理想设计,我建议您使用@Html.BeginForm来访问编辑功能的相应POST调用