I have developed an HTML form wizard that helps creating an object compose the data to send to the server.
I have a controller with two action methods as follow:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult SaveItem( TypeOneItem model, int customerID ) {
and
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult SaveItem( TypeTwoItem model, int customerID ) {
TypeOneItem and TypeTwoItem are both subclass of BaseItem. The class are defined this way
public class BaseItem
{
public int ItemID { get; set; }
public string Name { get; set; }
}
public class TypeOneItem : BaseItem
{
public int Property1 { get; set; }
public string Property2 { get; set; }
}
public class TypeTwoItem : BaseItem
{
public string Property3 { get; set; }
public int Property4 { get; set; }
public double Property5 { get; set; }
}
However, even if I am posting the right data to be binded to just one of the two concrete classes I get the error
"The current request for action 'SaveItem' on controller type 'ManageController' is ambiguous between the following action methods: System.Web.Mvc.ActionResult SaveItem(TypeOneItem, Int32) System.Web.Mvc.ActionResult SaveItem(TypeTwoItem, Int32)
"
Why does this happens? I do not want to change the server action name and hard code the difference on the UI wizard. Is there another way to solve this problem?