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