0
我有一個從服務器訪問數據的網絡API控制器:的Web API返回空值
public class ServicesController : ApiController
{
[AcceptVerbs("POST")]
public IList<TreeMenuItem> LoadMetadata()
{
List<TreeMenuItem> itemsMenu = new List<TreeMenuItem>();
TreeMenuItem dataSource = new TreeMenuItem("1", "DataSources", null);
itemsMenu.Add(dataSource);
return itemsMenu;
}
}
其由angularJS CONTROLER是呼叫:
angular.module('App').
controller('TreeMenuController', ["$scope", "$http", treeMenuController]);
function treeMenuController($scope, $http) {
var baseUrl = "api/Services/LoadMetadata";
$http.post(baseUrl)
.then(function (result) {
$scope.roleList = result.data;
});
};
在瀏覽器的網絡I具有:
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:application/json, text/plain, */*
Accept-Encoding:gzip,deflate
Content-Length:2
Content-Type:application/json;charset=UTF-8
請求負載 {}
響應頭:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Content-Length: 4
在響應選項卡:[{}]。
出了什麼問題?
你確定它是'result.data'而不僅僅是'result'嗎? – 2014-10-20 12:29:25
我嘗試了兩種方法,看看Response Tab表單網絡瀏覽器:這是我得到的:{{}] – BogdanIM 2014-10-20 12:32:42
您是否在Web API中放置了一個斷點 - 它到達那裏了嗎?你有另一個名稱LoadMetadata嗎? – MichaelLo 2014-10-20 12:47:30