asp.net-core-webapi

ASP.NET Core Web API route issue


I have a BaseController with a route defined as follows:

[ApiController]
[Route("trac/[controller]")]
public abstract class BaseController<T> : ControllerBase

And I have another controller inheriting from it:

public class HeadingsController: BaseController<IServices>
{
    [HttpGet("{controller}")]
    public async Task<ActionResult> ByController(int controller)
        => Ok(await this.Service.ByController(controller));
    ...
}

which matches perfectly in swagger

enter image description here

But when testing, the route is not matched:

enter image description here

I tried to put [FromRoute] in front - no change.

All other routes work as expected - including body and query params.

Any suggestions on that?


Solution

  • managed it

    param named controller causes issues

    interferes with api naming convention, no issues for swagger though

    changed to controllerId and all works