0
我试图在MVC 4视图上有多个提交按钮,然后根据点击的按钮选择在控制器中采取的操作。但是,控制器无法识别哪个按钮被点击并始终显示为空。控制器看不到哪个按钮被点击
我在做什么错?
//View
@using (Html.BeginForm())
{
<button type = "submit" name = "btn" value = "save_new" id = "SaveNew" > Save & amp; New </button>
<button type = "submit" name = "btn" value = "save_close" id = "SaveClose" > Save & amp; Close </button>
}
//Controller
public ActionResult PortalAccountMapping(PortalAccountMappingModel model, string btn)
{
if (btn == "save_new")
{
// the form was submitted using the Save&New button
}
else if (btn == "save_close")
{
// the form was submitted using the Save&Close button
}
else
{
UpdateModel(model.Grid.UpdateParams);
return Json(model.GetRows());
}
return View();
}
btn值始终为空。
我不知道什么是错在那里做的 - 我用不用的问题这种方法...... –
你有'[HttpPost]上面的'你的行动? – Thennarasan
是的,我确实在ActionResult上面有[HttpPost]。单击按钮确实会导致控制器击中公共ActionResult PortalAccountMapping,但btn始终为空。 – GoGetSOme