We can do this task in many ways. But one simple approach to do this is using an “attribute-based solution”.

index

index save action

To do this we can do it like the following.

Step 1

Create a class, HttpParamActionAttribute.cs, in an ASP.Net MVC application.

  1. using System;
  2. using System.Reflection;
  3. using System.Web.Mvc;
  4. namespace MultipleButtonClick
  5. {
  6. public class HttpParamActionAttribute : ActionNameSelectorAttribute
  7. {
  8. public override bool IsValidName(ControllerContext controllerContext, string actionName, MethodInfo methodInfo)
  9. {
  10. if (actionName.Equals(methodInfo.Name, StringComparison.InvariantCultureIgnoreCase))
  11. return true;
  12. var request = controllerContext.RequestContext.HttpContext.Request;
  13. return request[methodInfo.Name] != null;
  14. }
  15. }
  16. }
Step 2

Create a Home control and write some action like this:
  1. using System.Web.Mvc;
  2. namespace MultipleButtonClick.Controllers
  3. {
  4. public class HomeController : Controller
  5. {
  6. //
  7. // GET: /Home/
  8. public ActionResult Index()
  9. {
  10. ViewBag.msg = "I am from Index action.";
  11. return View();
  12. }
  13. [HttpPost]
  14. [HttpParamAction]
  15. public ActionResult Save()
  16. {
  17. ViewBag.msg = "I am from Save action.";
  18. return View();
  19. }
  20. [HttpPost]
  21. [HttpParamAction]
  22. public ActionResult Delete()
  23. {
  24. ViewBag.msg = "I am from Delete action.";
  25. return View();
  26. }
  27. }
  28. }
Step 3

Create a View, Index, and write the HTML code like this:

  1. @{
  2. ViewBag.Title = "Index";
  3. }
  4. <h2>Index</h2>
  5. @ViewBag.msg
  6. <br /> <br />
  7. @using (@Html.BeginForm())
  8. {
  9. <input type="submit" name="Save" value="Save" />
  10. <input type="submit" name="Delete" value="Delete" />
  11. }