In this article I will explain with an example, how to call multiple Action methods using one Single Form in ASP.Net MVC Razor.
One Form in a View can do a POST submission to one Action method in Controller and hence in order to call multiple Action methods using one single Form in a View, a Switch case has to be implemented inside the Action method.
The Switch case detects the clicked Submit button by fetching its Value from the Request.Form collection and the appropriate Action method will be called in ASP.Net MVC Razor.
 
 
Controller
The Controller consists of four Action methods.
Index Action method for handling GET operation
Inside this Action method, simply the View is returned.
 
Index Action method for handling POST operation
Inside this Action method, the value of the clicked Submit button is fetched using its Name from the Request.Form collection and appropriate Action method is called.
 
Save Action method for handling POST operation – Button 1
This Action method gets called on the click of the first button i.e. Save button. It sets a string message in TempData object indicating that the Save button was clicked and then it redirects to the Index view.
 
Cancel Action method for handling POST operation – Button 2
This Action method gets called on the click of the second button i.e. Cancel button. It sets a string message in TempData object indicating that the Cancel button was clicked and then it redirects to the Index view.
public class HomeController : Controller
{
    // GET: Home
    public ActionResult Index()
    {
        return View();
    }
 
    [HttpPost]
    public ActionResult Index(string submit)
    {
        switch (submit)
        {
            case "Save":
                return (Save());
            case "Cancel":
                return (Cancel());
        }
        return View();
    }
 
    [HttpPost]
    public ActionResult Save()
    {
        TempData["Message"] = "You clicked Save!";
        return RedirectToAction("Index");
    }
 
    [HttpPost]
    public ActionResult Cancel()
    {
        TempData["Message"] = "You clicked Cancel!";
        return RedirectToAction("Index");
    }
}
 
 
View
The following View markup consists of a Form created using Html.BeginForm Helper methods and the Form consists of two HTML Submit buttons.
Note: It is very important for all the Submit buttons to have a same Name attribute. In this example, the Name attribute value is set to Submit.
 
At the end, there’s a JavaScript method that displays the TempData object message using JavaScript Alert Message Box.
@{
    Layout = null;
}
 
<!DOCTYPE html>
 
<html>
<head>
    <meta name="viewport" content="width=device-width"/>
    <title>Index</title>
</head>
<body>
    @using (Html.BeginForm("Index", "Home", FormMethod.Post))
    {
        <table>
            <tr>
                <td><input type="submit" id="btnSave" name="Submit" value="Save"/></td>
                <td><input type="submit" id="btnCancel" name="Submit" value="Cancel"/></td>
            </tr>
        </table>
    }
 
    @if (TempData["Message"] != null)
    {
        <script type="text/javascript">
            window.onload = function () {
                alert('@TempData["Message"]');
            };
        </script>
    }
</body>
</html>
 
 
Screenshot
Calling multiple Action methods using Single Form in ASP.Net MVC
 
 
Downloads