Let's say I have the following class structure:
public class BaseClass
{
public string TestString { get; set; }
}
public class CityClass: BaseClass
{
public string City { get; set; }
}
public class TownClass:BaseClass
{
public string Town { get; set; }
}
I want to create a controller that has 2 post methods
public class TestController : ApiController
{
public IHttpActionResult Post(TownClass model)
{
}
public IHttpActionResult Post(CityClass model)
{
}
}
If I post to the end points with JSON data as follows:
http://localhost:30868/api/test
{"City":"New York","TestString":"Testing"}
or
{"Town":"Somewhere small","TestString":"Testing"}
I receive an error: Multiple actions were found that match the request
If there any way to get this working with the child/base class scenario?
I'd like to do this without defining new routes.