[英]Calling a controller action MVC5
好的,所以我得到了控制器中的操作,代码是:
[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中是新手,所以请耐心等待。
作为记录在这里 : -
2.指向动作的超链接或锚标记始终是HttpGet。
尝试在下面的代码中放入GET,因为默认情况下它需要[HttpGet]
所以请删除[HttpPost]
属性
[HttpGet]
public ActionResult SaveRow(int? id)
{
//some db operations.
return RedirectToAction("Index");
}
作为MVC的理想设计,我建议您使用@Html.BeginForm
来访问edit functionailty的垂直POST
调用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.