Is it legal to have controller action methods that are generic? For example, I made this:
[Route("api/[controller]")]
public class NumbersController : Controller
{
[HttpPost("{orderType}")]
public async Task<IActionResult> Create<T>(
[FromBody]
[ModelBinder(BinderType = typeof(OrderModelBinder))]
Order<T> order) where T : IOrder
{
//....
}
My custom OrderModelBinder
checks the {orderType} path segment to determine the concrete IOrder
used to create the Order<T>
.
When I run the code, I get a 404. I am not sure if it is because I've done something wrong, or if ASP.NET simply does not support this.
Perhaps instead of a custom model binder, I should use a custom IActionInvoker?
I'm working with both ASP.NET Core and ASP.NET Web API 2.x. I suspect if this can be done at all, it will be a similar technique either way.