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

后端 未结 30 2991
一个人的身影
一个人的身影 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:45

    //model
        public class input_element
            {
             public string Btn { get; set; }
            }   
    
    //views--submit btn can be input type also...
        @using (Html.BeginForm())
        {
                
                    
                
        }
    
    //controller
    
        public ActionResult About()
            {
                ViewBag.Message = "Your app description page.";
                return View();
            }
    
            [HttpPost]
            public ActionResult About(input_element model)
            {
                    if (model.Btn == "verify")
                    {
                    // the Verify button was clicked
                    }
                    else if (model.Btn == "save")
                    {
                    // the Save button was clicked
                    } 
                    else if (model.Btn == "redirect")
                    {
                    // the Redirect button was clicked
                    } 
                    return View();
            }
    

提交回复
热议问题