Aug 8, 2015

How do you handle multiple submit buttons in ASP.NET MVC Framework

Is there some easy way to handle multiple submit buttons from the same form? Example:



<% Html.BeginForm("MyAction", "MyController", FormMethod.Post); %>
<input type="submit" value="Send" />
<input type="submit" value="Cancel" />
<% Html.EndForm(); %>



razor:

<!form action="" method="post"> 

<!input type="submit" value="Save" name="action:Save" />

 <i!nput type="submit" value="Cancel" name="action:Cancel" /> </form>



and controller:


[HttpPost]

 [MultipleButton(Name = "action", Argument = "Save")]
 public ActionResult Save(MessageModel mm)
 { ...
 } 

[HttpPost] 
[MultipleButton(Name = "action", Argument = "Cancel")] 
public ActionResult Cancel(MessageModel mm)
 { ...
 }



 

No comments:

Post a Comment