Let's say I have a page with 2 forms that both submit different data on the same page, one submits two ID's, and the other submits only 1 ID. They are both posting back to the same page (itself). Here is what the HTML would look like...
<form method="post">
<select name="regID">
...
</select>
<select name="jobID">
...
</select>
<input type="submit" value="Add">
</form>
<form method="post">
<button name="ID" type="submit" value="@ID">Remove</button>
</form>
Now, to handle the first form in the controller I can do
[HttpPost]
public ActionResult Index(int regID, int jobID)
{
....
}
However, if I try to handle the second form by adding
[HttpPost]
public ActionResult Index(int ID)
{
....
}
When I click the submit button, I will now get the error
The current request for action 'Index' on controller type 'UserJobController' is ambiguous between the following action methods:
System.Web.Mvc.ActionResult Index(Int32) on type careerninja.Controllers.UserJobController
System.Web.Mvc.ActionResult Index(Int32, Int32) on type careerninja.Controllers.UserJobController
So, is it possible in the controller to overload the [HttpPost] method with different values to handle 2 different sets of form data, or is this not possible? Is there another solution I might not be grasping to handle this sort of issue?
Basically, for the second form I want to have a "Remove" button that when clicked, calls the controller to remove the item, removes the item, then returns the Index() view.