I'll admit, this seemed so simple and stupid to me, but I had to messs with it a while to get it to work the way that I wanted it to work. On a web forms page, you would just tell the button which method to fire after being pushed, but MVC figures things out for you. Maddeningly.
So, all I want to figure out here is...how do I make sure that each button does something different? I want each button to just state the value of the button in the box below.
It turns out that all I need to do is give a "formaction"
@using (Html.BeginForm())
{
<input type="submit" formaction="PrimeButton" value="Primary" class="btn btn-primary" />
<input type="submit" formaction="DangerButton" value="Danger" class="btn btn-danger" />
<input type="submit" formaction="DarkButton" value="Dark" class="btn btn-dark" />
}
<div class="box" >
@ViewBag.Result
</div>
By naming the buttons the name of the action that I want to use, I just need to create those actions in the controller
public ActionResult PrimeButton()
{
ViewBag.Result = "Primary";
return View("MultiButtons");
}
public ActionResult DangerButton()
{
ViewBag.Result = "Danger";
return View("MultiButtons");
}
public ActionResult DarkButton()
{
ViewBag.Result = "Dark";
return View("MultiButtons");
}