How to use multiple submit button in mvc

Jak
Jak
908 Points
132 Posts

How to use multiple submit button in mvc?

Views: 9534
Total Answered: 1
Total Marked As Answer: 1
Posted On: 11-Jan-2015 14:40

Share:   fb twitter linkedin
Answers
Rahul Maurya
Rahul M...
4916 Points
27 Posts
         

Hi,

Try this. You can take the value of button by setting the name attribute as same to all the submit button:

@using (Html.BeginForm("Create", "Home", FormMethod.Post, new { id = "submitForm" }))
{
@Html.TextBoxFor(m => m.Name, new { maxlength = 50 })
 
 <button type="submit" id="btnSave" name="command" value="Save">Save</button>
 <button type="submit" id="btnSubmit" name="command" value="Cancel"/>
}
public ActionResult Create(YourModel obj,string command)
{
 
//from here you can get the value of button you click
if(command="Save")
{
 
}
else if(command=="Cancel")
{
}
else
{
return RedirecToAction("Index");
}
return View();
 
}
Posted On: 11-Jan-2015 14:42
 Log In to Chat