繁体   English   中英

找不到与请求URI匹配的HTTP资源

[英]No HTTP resource was found that matches the request URI

这是我的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实例化时,我都会收到一条错误消息:

“ {” Message“:”未找到与请求URI相匹配的HTTP资源' http:// localhost / Services / HumanResources / api / Document / GetFileContents?DocumentId = 4 '。“,” MessageDetail“:”未找到任何操作在与请求匹配的控制器“文档”上。“}”

我在此Service文件中还有其他控制器,可以很好地调用它。 我猜我的语法有问题吗? 请帮助,我在这里环顾四周,但找不到与我的问题有关的特定内容。 谢谢!

更改您的JS参数DocumentId以匹配您的控制器ID。

$.ajax({
  type: "GET",
  //"Document/GetByReview?reviewId=" + that.selectedReview.ReviewId;
  url: constants.serviceUrl + "Document/GetFileContents?id=" + docId,
  contentType: "application/json; charset=utf8",
});

asp.net Web API给了我同样的错误,但是我用不同的方法解决了这个问题:

第一种方法

我将AclController的控制器名称更改为AuthorizeController并解决了我的问题。

第二种方法

如果您将方法参数类型与string,int,bool等一起使用,则此方法可能会解决您的问题。types会出现此错误,并且不使用string,int,bool等。类型仅使用类或接口等。你的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM