I have got the following on an API controller:
public void UpdateClient(Client client)
{
try
{
if (ModelState.IsValid)
{
db.Entry(client).State = EntityState.Modified;
db.SaveChanges();
}
}
catch
{
throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound));
}
}
And the following on the page:
$.ajax({
url: "api/client/UpdateClient",
type: "PUT",
contentType: 'json',
data: ko.toJSON(model.selectedClient()),
success: function (result) {
getClients();
$("#loader").hide();
},
failure: function (result) {
alert(result.d);
$("#loader").hide();
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("An error occurred, please try again.");
$("#loader").hide();
}
});
But this gives the error 405 Method Not Allowed, can anyone see where I may have gone wrong? For reference the url for the api is ok as I use the same api controller for other functions too.
Also the selectedClient() is a Client object received via WebApi so should match perfectly to PUT up again.
See Question&Answers more detail:os