In this question disabling the submit button to prevent multiple postbacks was a viable solution to stop (non-malicious) users from posting back multiple times.
This option doesn't work well if you have a view with multiple submit buttons. Take the following example.
//View:
@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>
}
//Controller:
[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();
}
In the view, there are three different submit actions. If the buttons are disabled, then their values won't be passed and the controller will not know which button triggered the submit. (The controller always gets null.) Unfortunately, the submitdisabledcontrols attribute does not seem to solve this problem in MVC. Does anybody know how to pass disabled control's values to the server?