The button name is not being passed to my action method.
Here is my view (simplified):
@using (Html.BeginForm("HandleSubmit", "Home", FormMethod.Post))
{
<input id="btnAddLineItem" type="submit" name="AddLineItem" value="AddLineItem" />
}
Here’s the controller method:
[HttpPost, ActionName("HandleSubmit")]
public ActionResult HandleSubmit(int? id, string btnSubmit)
{
switch (btnSubmit)
{
case "AddLineItem":
break;
case "AddNewOrder":
break;
}
return View("OrderDetails");
}
The btnSubmit value is always null. What do I need to do differently?
The
nameis what gets bound to your method signature, not theid.Use the following:
Remember the form post will send a
multipart/form-datacollection ofname/valuepairs to the server.