【发布时间】:2016-09-13 12:24:49
【问题描述】:
我正在尝试将 IEnumerable 从 Web api 控制器发送到 AngularJs 控制器。 我使用的代码是
网页接口:
readonly InventoryEntities _db = new InventoryEntities();
public IEnumerable<FDVOEligibilityRequest> Get()
{
return _db.FDVOEligibilityRequests.AsEnumerable();
}
AngularJS:
//get all customer information
$http.get("/api/Customer/").success(function (data) {
$scope.requests = data;
$scope.loading = false;
})
.error(function () {
$scope.error = "An Error has occured while loading posts!";
$scope.loading = false;
});
这很好用,但现在我使用 linq 来包含相关表,但它不起作用。 angularJs 代码是一样的。 我做错了什么?
readonly InventoryEntities _db = new InventoryEntities();
public IEnumerable<FDVOEligibilityRequest> Get()
{
return _db.FDVOEligibilityRequests
.Include("FDVOEligibilityRequestMandatoryField")
.Include("FDVOEligibilityRequestDCCField").AsEnumerable();
}
我确实在控制器中获得了我想要的数据,但是当我尝试将其发送回 angular 时,我得到一个 500(内部服务器错误)angular.js:10722
这就是 FDVOEligibilityRequest 在新的 Web Api 控制器中的样子
public partial class FDVOEligibilityRequest
{
public int Id { get; set; }
public string TestName { get; set; }
public string GroupName { get; set; }
public int MandatoryFieldsID { get; set; }
public int DCCFieldsID { get; set; }
public virtual FDVOEligibilityRequestMandatoryField FDVOEligibilityRequestMandatoryField { get; set; }
public virtual FDVOEligibilityRequestDCCField FDVOEligibilityRequestDCCField { get; set; }
}
【问题讨论】:
-
不起作用是什么意思?你得到的是什么而不是预期的结果?
-
我在环侧收到错误
-
您的新旧 Web Api 控制器的返回类型是相同的,但您是否在新的控制器中添加了属性?我要问的是,您的模型 FDVOEligibilityRequest 仍然是包含语句的有效模型吗?
-
这是 FDVOEligibilityRequest 在新的 Web Api 控制器中的样子
-
公共部分类 FDVOEligibilityRequest { public int Id { get;放; } 公共字符串 TestName { 获取;放; } 公共字符串组名 { 获取;放; } 公共 int MandatoryFieldsID { 获取;放; } 公共 int DCCFieldsID { 获取;放; } 公共虚拟 FDVOEligibilityRequestMandatoryField FDVOEligibilityRequestMandatoryField { 获取;放; } 公共虚拟 FDVOEligibilityRequestDCCField FDVOEligibilityRequestDCCField { 获取;放; } }
标签: angularjs linq http asp.net-web-api get