0

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.

Sun
  • 4,458
  • 14
  • 66
  • 108
  • Possible duplicate of [Overload web api action method based on parameter type](https://stackoverflow.com/questions/14353466/overload-web-api-action-method-based-on-parameter-type) – Igor Apr 26 '18 at 13:49
  • That does not help – Sun Apr 26 '18 at 14:27
  • `If there any way to get this working with the child/base class scenario?` <= No. Even if the classes were unrelated it would still not work. By default you can't overload a web method based on the parameter type. – Igor Apr 26 '18 at 14:29

0 Answers0