In .Net 5.0 API, I have an action on which I have applied multiple attribute routes as defined below
[HttpGet, Route("Get/{id?}"), Route("{id}")]
public void Get(long id)
{
//do something
}
With this routing, the following paths work fine
-
api/Controller/1 -
api/Controller/Get/1
However, if I pass the id as a query parameter, I always get 0 in 'id'.
e.g.
api/Controller/Get?id=1.
Any idea what might be causing this issue and how it can be fixed?
Just tested using both net 5 and net 6 , VS 2022 and Postman
it is working properly
I've used this controller, action
UPDATE
but if I add [ApiController] attribute then query string id is 0
It seems that ApiController is not supposed to have a query string at all. It doesn't work even if I change route to this
UPDATE 2
See PO answer how to make ApiController to accept the parameters from a query string.