从jqGrid的问题调用asp.net网页API DELETE
我想援引jqGrid的ASP.net WEB API的DELETE方法。但是我得到的消息 - 错误状态:不允许的方法错误code:405。
I am trying to invoke DELETE method of ASP.net WEB API from jqGrid. However I get message - "Error Status: 'Method Not Allowed'. Error code: 405".
下面是详细信息。
的jqGrid code -
JQGrid code-
$("#employeeSalarysGrid").jqGrid('navGrid', '#employeeSalarysPager',
{
add: true,
edit: true,
del: true
},
editOption,
addOption,
delOption);
var delOption = {
caption: "Delete",
msg: "Delete selected record(s)?",
bSubmit: "Delete", bCancel: "Cancel",
mtype: "DELETE",
url: 'http://localhost:50570/api/Test/'
};
的ASP.NET Web API方法:
ASP.NET Web API method:
public HttpResponseMessage Delete(string id)
{
//code for processing delete request
}
我已经追查使用招发送的请求。下面是请求的详细信息:
I have traced the request sent using Fiddler. Below is the request details:
DELETE http://localhost:50570/api/Test HTTP/1.1
Accept: */*
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Referer: http://localhost:53055/Views/Test.aspx
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko
Host: localhost:50570
Content-Length: 13
Connection: Keep-Alive
Pragma: no-cache
oper=del&id=2
请注意参数ID = 2的请求的发送正文,且没有查询字符串,我相信应该是不错。
Please note parameter Id=2 is sent in the body of request and not query string, which I believe should be fine.
请让我知道原因,您的想法,为什么没有被调用删除方法。
Please let me know your thoughts on reason why delete method is not getting invoked.
您应该DELETE请求清除体内,并在网址的结尾追加ID。 答案(或这个老之一)描述了实施细则。我将严格建议您删除的http://本地主机:50570
preFIX从那里使用,并使用例如 URL网址:'/ API /测试/
而不是网址:的http://本地主机:50570 / API /测试/
。请参见这里阿贾克斯的限制。
You should remove the body from DELETE request and append id at the end of the URL. The answer (or this old one) describes the implementation details. I would strictly recommend you to remove http://localhost:50570
prefix from URLs which you use and use for example url: '/api/Test/'
instead of url: 'http://localhost:50570/api/Test/'
. See here for restrictions of Ajax.