No HTTP resource was found that matches the request URI

蓝咒 提交于 2020-01-07 02:40:41

问题


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!


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/34143844/no-http-resource-was-found-that-matches-the-request-uri

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!