简体   繁体   English

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

[英]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.

相关问题 未找到与Angular 2中的请求URI匹配的HTTP资源 - No HTTP resource was found that matches the request URI in Angular 2 找不到与请求URI&#39;MyUrl&#39;匹配的HTTP资源 - No HTTP resource was found that matches the request URI 'MyUrl' 获取没有与请求URI匹配的HTTP资源 - Getting No HTTP resource was found that matches the request URI 找不到与webapi中的请求URI匹配的HTTP资源 - No HTTP resource was found that matches the request URI in webapi 未找到与请求URI匹配的HTTP资源,未找到与控制器匹配的类型 - No HTTP resource was found that matches the request URI, No type was found that matches the controller 路由错误:找不到与请求URI匹配的HTTP资源 - Routing error: No HTTP resource was found that matches the request URI 自定义“找不到与请求uri匹配的http资源”消息 - Customizing “No http resource was found that matches the request uri” message 未找到与请求 URI 匹配的 HTTP 资源,我需要解决方案 - No HTTP resource was found that matches the request URI, I need solutions 我收到错误“没有找到与请求 URI 匹配的 HTTP 资源” - I am getting error “No HTTP resource was found that matches the request URI” 为什么这里“找不到与请求 URI 匹配的 HTTP 资源”? - Why is it that "No HTTP resource was found that matches the request URI" here?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM