0

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>
asked May 22, 2014 at 21:31

1 Answer 1

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(){});
answered May 22, 2014 at 21:42
1
  • Thanks a lot, that worked! But I also had a mistake in my app.js, I missed to pass the result to the function:-) Commented May 22, 2014 at 21:51

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.