2015-12-07 93 views
0

这里是我的ajax呼叫时,主叫GetFileContents匹配:无HTTP资源发现,请求URI

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://localhost/Services/HumanResources/api/Document/GetFileContents?DocumentId=4'。“,”MessageDetail“匹配的HTTP资源:”No 在与“ ”请求匹配的控制器“文档”

。我有这个服务文件中的其他控制器,我可以称之为完美。我猜我的语法错了吗?请帮忙,我环顾四周,但找不到具体的问题。谢谢!

回答

0

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

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

谢谢!!那是什么错了呢。我不知道他们必须是同一个名字。现在我做:) –

0

同样的错误给我的asp.net web api,但我用不同的方法和方法解决了这个问题;

第一种方法

我AclController改控制器名AuthorizeController和解决我的问题。

第二种方法

也许如果你使用的方法参数字符串,整数,布尔等类型的类型,然后取这个错误,不使用字符串,整数,布尔等类型的这个方法解决你的问题只使用类或接口等类型,然后可能解决你的问题。

相关问题