[英]No HTTP resource was found that matches the request URI
Here is my ajax call which is calling GetFileContents: 这是我的ajax调用,它正在调用GetFileContents:
views.titleClick = function (e) {
var grid = $("#documentsGrid").data("kendoGrid");
var docId = grid._data[0].DocumentId;
$.ajax({
type: "GET",
//"Document/GetByReview?reviewId=" + that.selectedReview.ReviewId;
url: constants.serviceUrl + "Document/GetFileContents?DocumentId=" + docId,
contentType: "application/json; charset=utf8",
})
};
Below is my Controller GetFileContents 以下是我的控制器GetFileContents
[HttpGet]
public HttpResponseMessage GetFileContents(int id)
{
DataResponseSingle<Document> result = BusinessAccess.GetById(id);
if (result.ResponseType != ResponseType.Success)
{
return CreateHttpResponse(result);
}
if (result.Data == null || result.Data.DocumentData == null)
{
return CreateHttpResponse(ResponseType.NotFound);
}
return CreateStreamContentHttpResponse(result.Data.DocumentData, "application/octet-stream", result.Data.Name);
}
Whenever titleClick gets instantiated I get an error saying 每当titleClick实例化时,我都会收到一条错误消息:
"{"Message":"No HTTP resource was found that matches the request URI ' http://localhost/Services/HumanResources/api/Document/GetFileContents?DocumentId=4 '.","MessageDetail":"No action was found on the controller 'Document' that matches the request."}" “ {” Message“:”未找到与请求URI相匹配的HTTP资源' http:// localhost / Services / HumanResources / api / Document / GetFileContents?DocumentId = 4 '。“,” MessageDetail“:”未找到任何操作在与请求匹配的控制器“文档”上。“}”
. 。 I have other controllers in this Service file which I am able to call perfectly fine. 我在此Service文件中还有其他控制器,可以很好地调用它。 I am guessing something wrong with my syntax ? 我猜我的语法有问题吗? Please help , I looked around here but could not find something specific to my problem. 请帮助,我在这里环顾四周,但找不到与我的问题有关的特定内容。 Thanks! 谢谢!
Change your JS param DocumentId to match your controller id. 更改您的JS参数DocumentId以匹配您的控制器ID。
$.ajax({
type: "GET",
//"Document/GetByReview?reviewId=" + that.selectedReview.ReviewId;
url: constants.serviceUrl + "Document/GetFileContents?id=" + docId,
contentType: "application/json; charset=utf8",
});
The same error has given to me by asp.net Web API but I solved that problem with different methods: asp.net Web API给了我同样的错误,但是我用不同的方法解决了这个问题:
First Method 第一种方法
I changed controller name with AclController to AuthorizeController and solved my problem. 我将AclController的控制器名称更改为AuthorizeController并解决了我的问题。
Second Method 第二种方法
Maybe this method solve your problem if you use method parameters type with string, int, bool etc. types then takes this error and don't use string, int, bool etc. types only use a class or interface etc. types then maybe solved your problem. 如果您将方法参数类型与string,int,bool等一起使用,则此方法可能会解决您的问题。types会出现此错误,并且不使用string,int,bool等。类型仅使用类或接口等。你的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.