I have a generic abstract controller in my ASP.Net core Web Api project with POST handling:
[HttpPost]
public async Task<IActionResult> Create([FromBody]R itemDto)
{
var ret = await _service.CreateNewItemAsync(itemDto);
return CreatedAtRoute("Get", new { id = ret.Id }, ret);
}
The 'Get' route looks like this:
[HttpGet("{id}", Name = "Get")]
public async Task<R> GetAsync(int id)
{
var model = await _service.GetItemAsync(id);
return model;
}
I have 2 Controller classes which inherit from this Base Controller and when I try to make a simple get on one of these Controllers I get the following error message:
Error 1: Attribute routes with the same name 'Get' must have the same template: Action: 'MyApi.WebApi.Controllers.FooController.GetAsync' - Template: 'api/foo/{id}' Action: 'MyApi.WebApi.Controllers.BarController.GetAsync' - Template: 'api/bar/{id}'
It is very obvious why I get this error, but I don't know what to do to use a named route in a base controller.
Can anyone point me in the right direction?