I have 2 actions with the same name, but one is an overload of the first that takes an int
parameter that the first overload does not have:
[HttpGet("Read")]
[Produces(typeof(IEnumerable<Client>))]
public async Task<IActionResult> Read()
...
[HttpGet("Read/{id}")]
[Produces(typeof(Client))]
public async Task<IActionResult> Read(int id)
I have tried every means I know to correctly define the route attribute template, and to form the correct URL to invoke the second action , with the parameter. Every try, using my code and PostMan, to invoke this action results in a 404.
The whole controller looks like this:
[Route("api/[controller]")]
[Produces("application/json")]
public class ClientsController : Controller
{
private readonly IDataService _clients;
public ClientsController(IDataService dataService)
{
_clients = dataService;
}
[HttpPost("Create")]
[Produces(typeof(int))]
public int Post([Bind("GivenName,FamilyName,GenderId,DateOfBirth,Id")] Client client)
{
var ret = _clients.Create(client);
return ret;
}
[HttpGet("Read")]
[Produces(typeof(IEnumerable<Client>))]
public async Task<IActionResult> Read()
{
var clients = await _clients.ReadAsync();
return Ok(clients);
}
[HttpGet("Read/{id}")]
[Produces(typeof(Client))]
public async Task<IActionResult> Read(int id)
{
var client = await _clients.ReadAsync(id);
if (client == null)
{
return NotFound();
}
return Ok(client);
}
[HttpPut("Update")]
public void Put([Bind("GivenName,FamilyName,GenderId,DateOfBirth,Id")] string json)
{
// NB Edit isn't saving.
var client = JsonConvert.DeserializeObject<Client>(json);
_clients.UpdateAsync(client);
}
[HttpDelete("Delete/{id:int}")]
public void Delete(int id)
{
}
}