I have a generic Web API controller that does CRUD which is like this:
public class BaseController : ApiController {
[HttpPost]
public virtual IHttpActionResult Post(T entity)
{
return Ok();
}
[HttpPut]
public virtual IHttpActionResult Put(T entity)
{
return Ok();
}
}
ObjectController is derived from BaseController but it overrides the Put Method
public class ObjectController : BaseController {
[HttpPut]
[Route("api/Object")]
public override IHttpActionResult Put(T entity)
{
return Ok();
}
}
I have no problem calling all methods in a controller when none is overridden. For example,
public class Object2Controller : BaseController { }
Invoking the POST method returns 405 method not allowed. What is wrong with my code?
EDIT This is not a duplicate question because I can call PUT in other controllers.
EDIT 2 Changed new to override(virtual) but still getting the same error
EDIT 3 Provided a working controller