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


To do this we can do it like the following.
Step 1
Create a class, HttpParamActionAttribute.cs, in an ASP.Net MVC application.
- using System;
- using System.Reflection;
- using System.Web.Mvc;
- namespace MultipleButtonClick
- {
- public class HttpParamActionAttribute : ActionNameSelectorAttribute
- {
- public override bool IsValidName(ControllerContext controllerContext, string actionName, MethodInfo methodInfo)
- {
- if (actionName.Equals(methodInfo.Name, StringComparison.InvariantCultureIgnoreCase))
- return true;
- var request = controllerContext.RequestContext.HttpContext.Request;
- return request[methodInfo.Name] != null;
- }
- }
- }
Create a Home control and write some action like this:
- using System.Web.Mvc;
- namespace MultipleButtonClick.Controllers
- {
- public class HomeController : Controller
- {
- //
- // GET: /Home/
- public ActionResult Index()
- {
- ViewBag.msg = "I am from Index action.";
- return View();
- }
- [HttpPost]
- [HttpParamAction]
- public ActionResult Save()
- {
- ViewBag.msg = "I am from Save action.";
- return View();
- }
- [HttpPost]
- [HttpParamAction]
- public ActionResult Delete()
- {
- ViewBag.msg = "I am from Delete action.";
- return View();
- }
- }
- }
Create a View, Index, and write the HTML code like this:
- @{
- ViewBag.Title = "Index";
- }
- <h2>Index</h2>
- @ViewBag.msg
- <br /> <br />
- @using (@Html.BeginForm())
- {
- <input type="submit" name="Save" value="Save" />
- <input type="submit" name="Delete" value="Delete" />
- }

Narinder SinghPosted Jun 23, 2018, 1:25 AM
Sir in different views we need to create a different attributes.............?
Chandradev PrasadPosted Nov 1, 2014, 2:58 AM
Thanks for comment. But i don't think that we can fire the action using Request.Form["Accept"]. It can be used to receive the data from preview page. Can you show me some article on this ?
ram jeyaramanPosted Oct 31, 2014, 6:23 AM
i have used Request.Form["Accept"] where "Accept" is the name of the submit of button............ this is also another idea/suggestion