---
title: "Handling multiple submit button in asp.net mvc"  
description: "Handling multiple submit button in asp.net mvc"  
author: "Anonymous User"  
published: 2014-10-07  
updated: 2014-10-07  
canonical: https://www.mindstick.com/forum/2323/handling-multiple-submit-button-in-asp-dot-net-mvc  
category: "asp.net mvc"  
tags: ["asp.net", "asp.net mvc"]  
reading_time: 1 minute  

---

# Handling multiple submit button in asp.net mvc

Is there some easy way to [handle multiple](https://www.mindstick.com/forum/159240/how-to-handle-multiple-exceptions-using-the-catch-block-in-java) submit buttons from the same [form](https://www.mindstick.com/forum/6/multi-form-mfc-application)? Example.\

```
<%
Html.BeginForm("MyAction", "MyController",FormMethod.Post); %><input type="submit" value="Send" /><input type="submit" value="Cancel" /><%Html.EndForm(); %>
```

Any idea how to do this in [ASP.NET](https://www.mindstick.com/articles/934/default-folders-available-inside-the-asp-dot-net-application-folder) [Framework](https://www.mindstick.com/forum/34615/software-framework-vs-library) [Beta](https://answers.mindstick.com/qa/30471/what-is-beta-version)? All examples I've googled for have single buttons in them.\

## Replies

### Reply by Anonymous User

Here is a mostly clean attribute-based solution to the [multiple](https://www.mindstick.com/blog/12797/iowa-is-expected-to-see-heavy-growth-in-multiple-sectors) submit button issue based heavily on the post and comments from.

```
[AttributeUsage(AttributeTargets.Method,
AllowMultiple = false, Inherited = true)]        public class MultipleButtonAttribute : ActionNameSelectorAttribute        {            public string Name { get; set; }            public string Argument { get; set; }             public override bool IsValidName(ControllerContext controllerContext, string actionName, MethodInfo methodInfo)            {                var isValidName = false;                var keyValue = string.Format("{0}:{1}", Name, Argument);                var value =
controllerContext.Controller.ValueProvider.GetValue(keyValue);                 if (value != null)                {                   
controllerContext.Controller.ControllerContext.RouteData.Values[Name] =Argument;                    isValidName = true;                }                 return isValidName;            }        }
```

**razor:**\

```
<form action="" method="post"> <input type="submit" value="Save" name="action:Save" /> <input type="submit" value="Cancel" name="action:Cancel" /></form>
```

**and controller:**\

```
[HttpPost]        [MultipleButton(Name = "action",
Argument = "Save")]        public ActionResult Save(MessageModel mm) { ... }         [HttpPost]        [MultipleButton(Name = "action",
Argument = "Cancel")]        public ActionResult Cancel(MessageModel mm) { ... }   
```


---

Original Source: https://www.mindstick.com/forum/2323/handling-multiple-submit-button-in-asp-dot-net-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
