在this question禁用提交按钮以防止多次回发是停止(非恶意)用户多次回发的可行解决方案。在MVC中防止多次提交
如果您有多个提交按钮的视图,则此选项无法正常工作。以下面的例子。
//查看:
@using (Html.BeginForm("Catalog", "Images", FormMethod.Post, new { onsubmit = "Utility.disable_buttons(this.id);", id = "catalog_form" }))
{
<p>
<input type="submit" name="btnSubmit" value="Clear" /> |
<input type="submit" name="btnSubmit" value="Catalog" /> |
<input type="submit" name="btnSubmit" value="Update" /> |
@Html.ActionLink("Back to List", "Index")
</p>
}
//控制器:
[HttpPost]
public ActionResult Catalog(string btnSubmit)
{
switch (btnSubmit)
{
case "Catalog":
//More differenter code
break;
case "Clear":
//Different code
break;
case "Nothing":
//Code
break;
}
return View();
}
在视图中,有三种不同的提交动作。如果这些按钮被禁用,那么它们的值将不会被传递,并且控制器将不知道哪个按钮触发了提交。 (控制器始终为空。)不幸的是,submitdisabledcontrols属性似乎不能解决MVC中的这个问题。有人知道如何将禁用控件的值传递给服务器吗?
我可能不得不为这个看似简单的问题开始赏金...... – Coda