I have searched on stackoverflow and google and have found many articles on the subject but I still can't seem to know what I am doing wrong! I really feeling desperate. E.g. How to handle two submit buttons on MVC view
I'm just trying to have three buttons in my view. I do hit the action in the controller, however, the string comparison does not work. For some reason, I cannot hit my breakpoints.
Here's my code: View:
@using RequestDB7mvc.Models
@model MainViewModel
@{
ViewBag.Title = "Main";
}
<div class="form-group">
@using (Html.BeginForm("Search4", "Requests", FormMethod.Post))
{
<input type="submit" value="Save" name="command" />
<input type="submit" value="Done" name="command" />
<input type="submit" value="Cancel" name="command" />
}
Controller:
[HttpPost]
public ActionResult Search4(MainViewModel model, string command)
{
if (command.Equals("Save"))
{
// Call action here...
string f = "break";
}
else if (command.Equals("Done"))
{
// Call another action here...
string f = "break";
}
else if (command.Equals("Cancel"))
{
// Call another action here...
string f = "break";
}
ViewBag.Msg = "Details saved successfully.";
return View();
}