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

后端 未结 30 3031
一个人的身影
一个人的身影 2020-11-21 07:16

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

<% Html.BeginForm(\"MyAction\", \"MyController\", FormMethod.Pos         


        
30条回答
  •  死守一世寂寞
    2020-11-21 07:36

    This is the technique I'd use and I don't see it here yet. The link (posted by Saajid Ismail ) that inspires this solution is http://weblogs.asp.net/dfindley/archive/2009/05/31/asp-net-mvc-multiple-buttons-in-the-same-form.aspx). It adapts Dylan Beattie's answer to do localization without any problems.

    In the View:

    <% Html.BeginForm("MyAction", "MyController", FormMethod.Post); %>
    
    
    <% Html.EndForm(); %>
    

    In the Controller:

    public class MyController : Controller 
    {
        public ActionResult MyAction(string button)
        {
             switch(button)
             {
                 case "send":
                     this.DoSend();
                     break;
                 case "cancel":
                     this.DoCancel();
                     break;
             }
        }
    }
    

提交回复
热议问题