2015-12-07 92 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和解決我的問題。

第二種方法

也許如果你使用的方法參數字符串,整數,布爾等類型的類型,然後取這個錯誤,不使用字符串,整數,布爾等類型的這個方法解決你的問題只使用類或接口等類型,然後可能解決你的問題。

相關問題