找不到与请求URI匹配的HTTP资源
这是我的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",
})
};
下面是我的控制器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);
}
无论何时实例化titleClick,我都会收到一条错误消息
Whenever titleClick gets instantiated I get an error saying
"{"消息:"找不到与请求URI匹配的HTTP资源' http://localhost/Services/HumanResources/api/Document/GetFileContents?DocumentId = 4 '.," MessageDetail:"否 在控制器文档"上找到与 请求.}"
"{"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."}"
.我在此Service文件中还有其他控制器,可以很好地调用它.我猜我的语法有问题吗?请帮助,我在这里四处张望,但找不到与我的问题有关的特定内容.谢谢!
. I have other controllers in this Service file which I am able to call perfectly fine. I am guessing something wrong with my syntax ? Please help , I looked around here but could not find something specific to my problem. Thanks!
更改您的JS参数DocumentId以匹配您的控制器ID.
Change your JS param DocumentId to match your controller id.
$.ajax({
type: "GET",
//"Document/GetByReview?reviewId=" + that.selectedReview.ReviewId;
url: constants.serviceUrl + "Document/GetFileContents?id=" + docId,
contentType: "application/json; charset=utf8",
});