This is what my controller looks like:
[Route("api/[controller]")]
[Produces("application/json")]
public class ClientsController : Controller
{
private readonly IDataService _clients;
public ClientsController(IDataService dataService)
{
_clients = dataService;
}
[HttpPost]
public int Post([Bind("GivenName,FamilyName,GenderId,DateOfBirth,Id")] Client model)
{
// NB Implement.
return 0;
}
[HttpGet("api/Client/Get")]
[Produces(typeof(IEnumerable<Client>))]
public async Task<IActionResult> Get()
{
var clients = await _clients.ReadAsync();
return Ok(clients);
}
[HttpGet("api/Client/Get/{id:int}")]
[Produces(typeof(Client))]
public async Task<IActionResult> Get(int id)
{
var client = await _clients.ReadAsync(id);
if (client == null)
{
return NotFound();
}
return Ok(client);
}
[HttpGet("api/Client/Put")]
public void Put(int id, [FromBody]string value)
{
}
[HttpGet("api/Client/Delete/{id:int}")]
public void Delete(int id)
{
}
}
Yet when I request the URL /api/Clients/Get
, as follows:
json = await Client.GetStringAsync("api/Clients/Get");
I get back the following exception:
AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all constraints satisfied:
Assessment.Web.Controllers.ClientsController.Index (Assessment.Web) Assessment.Web.Controllers.ClientsController.Details (Assessment.Web) Assessment.Web.Controllers.ClientsController.Create (Assessment.Web)
Client
is an HttpClient
. Please note that no GET action matched the route data, despite the same name, id
.
What could be wrong here?