Friday, 25 January 2019

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

 Handling Multiple Submit Buttons In ASP.NET MVC

Description:
In this example, we explain that how to handle multiple submit button in MVC form in .Net. Or how do you handle multiple submit buttons in Asp.Net MVC Framework. Alternatively, how to handle multiple submit buttons on single View in MVC.

Below is the code that are useful to handle multiple submit button on single form in MVC.
View:

<button class="btn btn-sm btn-primary" type="submit" name="button" value="Save">
                        <i class="fa fa-dot-circle-o"></i> Save
                    </button>
<button class="btn btn-sm btn-primary" type="submit" name="button" value="Save as New Template">
                        <i class="fa fa-dot-circle-o"></i> Save as New Template
                    </button>
Controller: 

[HttpPost]
        public IActionResult AddTemplate(Template objTemplate,string button)
        {
            try
            {
                if (button == "Save")
                {
                                                //Code for Save Button
                 }
Else
{
//Code for Save as New Template Button

}
            }
            catch (Exception ex)
            {
                Logger.WriteLog(ex);
                throw;
            }
        }

This entry was posted in :

1 comments: