【发布时间】:2014-12-03 13:54:20
【问题描述】:
我正在尝试从服务器获取测试客户列表。我知道 Web API 控制器正在从数据库接收数据,因为我有围绕它的单元/集成测试;但是,当我尝试将数据拉到我的角度控制器时,我会收到 500 状态码。
角度控制器:
var surchargeIndex = angular.module('surchargeIndex', []);
surchargeIndex.controller('SurchargeIndexController', function ($scope, customerService) {
$scope.customers = { Key: "", Value: "" };
customerService.getTest($scope);
});
surchargeIndex.service('customerService', [
'$http', function($http) {
this.getTest = function ($scope) {
return $http({
method: "GET",
url: "api/Customer/GetTest",
})
.success(function (data) {
$scope.customers = data;
})
.error(function () {
$scope.error = "Failed to load customers!";
});
}
}
]);
网页接口:
[RoutePrefix("api/Customer")]
public class CustomerController : ApiController
{
private readonly ICustomerService _service;
public CustomerController(ICustomerService service)
{
_service = service;
}
[Route("GetTest"), HttpGet]
public IEnumerable<IJsonResult> GetTest()
{
return _service.GetTest();
}
}
我错过了什么?
【问题讨论】:
-
你能检查一下 500 错误的详细信息吗?
-
@jadarnel27 它指出,资源加载失败。
-
能否在 C# 代码中设置断点并查看是否抛出异常?我知道您提到您已经围绕此代码进行了自动化测试,但最好只是验证某些内容没有出错。
标签: c# asp.net angularjs asp.net-web-api