Reputation: 993
I'm working on a ASP.NET WebApi / AngularJS project. For now I want to display a table. Going to '/api/Auftraege' shows the Json Data. But '/api/Auftaege/index' brings this error:
{"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."}
So I tried to change the property of the 'id' in the .edmx Diagram to 'nullable = true', because there are entries with zeros. That didn`t work.
Any idea what I can do? Am I missing something else besides the database? Perhaps the file path in the 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;
}
The ng-repeat within the Index.cshtml(If I run the Index.cshtml, then the error alert from the angular controller named ListCtrl pops up):
<tr ng-repeat="i in data">
<td>{{i.AngebotsNummer}}</td>
<td>{{i.VerkaeuferName}}</td>
<td>{{i.Bezeichnung}}</td>
</tr>
Upvotes: 0
Views: 1826
Reputation: 20014
If this is a WebApi REST Service you do not need or have to include the name of the method. You only refer to the Controller class without the word controller like this:
$http.get("/api/Auftraege").then(function(){});
Upvotes: 1