I’ve got an HttpGet on an API method with primitive parameters and would like to provide the option of passing parameters via the query OR route. I’ve just trashed half a day building various custom binders and such trying to figure this out to no avail.
I’d like this method to work with both /GetMyData/1
and /GetMyData?id=1
[HttpGet]
[Route("GetMyData/{id}")]
public async Task<ActionResult> GetMyData(int id)
{
return await _dataService.GetMyData(id).ConfigureAwait(false);
}
If I set to [Route("GetMyData")]
then /GetMyData?id=1
works. If I set to [Route("GetMyData/{id}")]
then /GetMyData/1
works. But if I have [Route("GetMyData")][Route("GetMyData/{id}")]
then only /GetMyData/1
works.
What am I missing here? I’m working with an ApiController in .NET Core 8.
Eric Evans is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.