【发布时间】:2014-05-22 21:31:45
【问题描述】:
我正在开发一个 ASP.NET WebApi / AngularJS 项目。现在我想显示一个表格。转到“/api/Auftraege”会显示 Json 数据。但是 '/api/Auftaege/index' 会带来这个错误:
{"Message":"The request is invalid.","MessageDetail":"The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Threading.Tasks.Task`1[System.Web.Http.IHttpActionResult] GetKDAuftraege(Int32)' in 'Vis3.Controllers.AuftraegeController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter."}
所以我尝试将 .edmx 图中的“id”属性更改为“nullable = true”,因为有些条目是零。那没用。
知道我能做什么吗?除了数据库之外,我还缺少其他东西吗?可能是 app.js 中的文件路径?
以防万一……
app.js:
function ListCtrl($scope, $http) {
$scope.data = [];
$http.get("/api/Auftraege/GetKDAuftraeges")
.then(function (result) {
// Success
angular.copy(result.data, $scope.data);
},
function () {
// Error
alert("Error");
});
}
WebApi-控制器:
// GET api/Auftraege
[HttpGet]
public IEnumerable<KDAuftraege> GetKDAuftraeges()
{
var result = db.KDAuftraeges.Take(50).ToList();
return result;
}
Index.cshtml 中的 ng-repeat(如果我运行 Index.cshtml,则会弹出来自名为 ListCtrl 的角度控制器的错误警报):
<tr ng-repeat="i in data">
<td>{{i.AngebotsNummer}}</td>
<td>{{i.VerkaeuferName}}</td>
<td>{{i.Bezeichnung}}</td>
</tr>
【问题讨论】:
标签: c# angularjs asp.net-mvc-4 asp.net-web-api