-->

Wednesday, July 30, 2014

How to Use Multiple Submit Button in MVC Razor

How to Use Multiple Submit Button in MVC Razor

The most common method to get the data on server from client side. Submit button on the form can be used to post all the form data to be used further by programmer. Generally one form only have a single submit because of user want to post data only once.

To submit data in different ways programmer can use more than one submit button. A form can have multiple submit buttons as per the requirement of programmer. We can send the button’s name on the button click.

The action should have the same name of the button to get the value of clicked button. Suppose all the button’s have same name as submit as written below:

<input type = "submit" name = "btnsubmit" value= "submit1" />
<input type = "submit" name = "btnsubmit" value= "submit2" />
<input type = "submit" name = "btnsubmit" value= "submit3" />

Now in controller’s action the variable should be of string type and name as “submit” as below:

[HttpPost]
public ActionResult SubmitData(string btnSubmit)
{
If (btnSubmit == "submit1")
{
//code to execute
}

If (btnSubmit == "submit2")
{
//code to execute
}

If (btnSubmit == "submit3")
{
//code to execute
}
}

According to this code we can implement different functionality on each submit button with all the data posted on the form. These button will only post the data containing as input on the form and also inside the form element.

Read other related articles

Also read other articles

© Copyright 2013 Computer Programming | All Right Reserved