405讯息,法不得与网页API [英] 405 Message, method not allowed with Web Api
本文介绍了405讯息,法不得与网页API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个API控制器上的以下内容:
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));
}
}
和页面上的以下内容:
$.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不允许的方法,任何人都可以看到我可能已经错了吗?作为参考的API的网址是好的,因为我用其他功能相同的API也控制器
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.
另外,selectedClient()通过的WebAPI收到一个客户端对象,因此应匹配完美地再次提了起来。
Also the selectedClient() is a Client object received via WebApi so should match perfectly to PUT up again.
推荐答案
看起来这两条线是错误的,我改变了他们如下:
Looks like these two lines were wrong, I changed them as follows:
contentType: 'application/json',
data: "{client: " + ko.toJSON(model.selectedClient()) + "}",
现在进去
这篇关于405讯息,法不得与网页API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文