---
title: "Handling Multiple submit button in asp.net mvc?"  
description: "Handling Multiple submit button in asp.net mvc?"  
author: "Pravesh Singh"  
published: 2014-11-18  
updated: 2014-11-18  
canonical: https://www.mindstick.com/forum/12629/handling-multiple-submit-button-in-asp-dot-net-mvc  
category: "asp.net mvc"  
tags: ["c#", "asp.net", "html", "handler"]  
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](https://www.mindstick.com/forum/1944/html-beginform-post-going-to-httpget-action-rather-than-httppost-in-ie-fine-in-chrome-and-firefox)("MyAction", "MyController", FormMethod.Post); %>

<[input](https://www.mindstick.com/forum/159209/how-can-i-read-convert-an-input-stream-into-a-string-in-java) type="submit" [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages)="Send" />

<input type="submit" value="[Cancel](https://answers.mindstick.com/qa/94501/how-can-i-cancel-my-singapore-flight-ticket)" />

<% 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? All examples I've googled for have single buttons in them.

## Replies

### Reply by Royce Roy

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 Maartin Balliauw.

```
[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/12629/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.
