WebApi AngularJS "The request is invalid" 错误



我正在做一个ASP。. NET WebApi/AngularJS项目。现在我想显示一个表。到'/api/auftrage '显示Json数据。但是'/api/auftage/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中的文件路径?

Just in case…

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-Controller:

// GET api/Auftraege
        [HttpGet]
        public IEnumerable<KDAuftraege> GetKDAuftraeges()
        {
            var result = db.KDAuftraeges.Take(50).ToList();
            return result;
        }

索引内的ng-repeat。(如果我运行索引。然后从名为ListCtrl的angular控制器弹出错误警报):

<tr ng-repeat="i in data">
    <td>{{i.AngebotsNummer}}</td>
    <td>{{i.VerkaeuferName}}</td>
    <td>{{i.Bezeichnung}}</td>
</tr>

如果这是一个WebApi REST服务,你不需要也不必须包含方法名。你只能像这样引用Controller类而不使用Controller这个词:

 $http.get("/api/Auftraege").then(function(){});

相关内容

最新更新