Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using two submit buttons inside single form

I have a form with two submit buttons in my asp.net mvc (C#) application. When i click any submit button in Google Chrome, by default the value of submit button is the first submit button's value.

Here is the html:

 <input type="submit" value="Send" name="SendEmail" />
 <input type="submit" value="Save As Draft" name="SendEmail" />
 <input type="button" value="Cancel" />

When i click the Save As Draft button, in the action of the controller, it gets "Send" as the value for SendEmail.

Here is the action:

public ActionResult SendEmail(string SendEmail, FormCollection form)
 {
       if(SendEmail == "Send")
       {
          //Send Email
       }
       else
       {
          //Save as draft
       }
       return RedirectToAction("SendEmailSuccess");
 }

When i get the value from FormCollection, it shows "Send". i.e. form["SendEmail"] gives Send

What may be the problem or work around i need to do to get the actual value of the clicked submit button?

like image 979
Prasad Avatar asked Mar 11 '10 06:03

Prasad


People also ask

Can a form have 2 submit buttons?

yes, multiple submit buttons can include in the html form. One simple example is given below.

Can an HTML form have two submit buttons?

Let's learn the steps of performing multiple actions with multiple buttons in a single HTML form: Create a form with method 'post' and set the value of the action attribute to a default URL where you want to send the form data. Create the input fields inside the as per your concern. Create a button with type submit.

How can we use multiple submit button in single form in PHP?

Having multiple submit buttons and handling them through PHP is just a matter of checking the the name of the button with the corresponding value of the button using conditional statements. In this article I'll use both elseif ladder and switch case statement in PHP to handle multiple submit buttons in a form.


1 Answers

Show this page.

ASP.NET MVC – Multiple buttons in the same form - David Findley's Blog

Create ActionMethodSelectorAttribute inherit class.

like image 111
takepara Avatar answered Sep 23 '22 22:09

takepara