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>
1 Answer 1
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(){});
-
Thanks a lot, that worked! But I also had a mistake in my app.js, I missed to pass the result to the function:-)oldsport– oldsport2014年05月22日 21:51:28 +00:00Commented May 22, 2014 at 21:51
Explore related questions
See similar questions with these tags.