Is there some easy way to handle multiple submit buttons from the same form? For example:
<% Html.BeginForm(\"MyAction\", \"MyController\", FormMethod.Pos
Eilon suggests you can do it like this:
If you have more than one button you can distinguish between them by giving each button a name:
In your controller action method you can add parameters named after the HTML input tag names:
public ActionResult DoSomeStuff(string saveButton, string cancelButton, ... other parameters ...) { ... }If any value gets posted to one of those parameters, that means that button was the one that got clicked. The web browser will only post a value for the one button that got clicked. All other values will be null.
if (saveButton != null) { /* do save logic */ } if (cancelButton != null) { /* do cancel logic */ }
I like this method as it does not rely on the value property of the submit buttons which is more likely to change than the assigned names and doesn't require javascript to be enabled
See: http://forums.asp.net/p/1369617/2865166.aspx#2865166