简体   繁体   中英

No HTTP resource was found that matches the request URI

Here is my ajax call which is calling 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

        [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

"{"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."}"

. 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!

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",
});

The same error has given to me by asp.net Web API but I solved that problem with different methods:

First Method

I changed controller name with AclController to AuthorizeController and solved my problem.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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