APIコントローラーで次のものを取得しました:
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));
}
}
そして、ページ上の次のとおりです。
$.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();
}
});
しかし、これによりエラー 405 Method Not Allowed が発生します。どこが間違っているのか誰にもわかりますか? 参考までに、他の機能にも同じAPIコントローラーを使用しているため、APIのURLは問題ありません。
また、selectedClient() は WebApi 経由で受信した Client オブジェクトであるため、完全に一致して PUT を再開する必要があります。