Using entity framework I scaled a model 'beer.cs'
public class Beer
{
[Key]
public int ID { get; set; }
public bool HasTasted {get; set; }
public string Name { get; set; }
}
I took the automated code from BeersController and switched it to output Json
public ActionResult Index()
{
return View(db.Beers.ToList());
}
public ActionResult IndexVM()
{
return Json(db.Beers.ToList(), JsonRequestBehavior.AllowGet);
}
Now the problem is, I'm getting json back without a model name so it looks like this
[{"ID":1,"HasTasted":true,"Name":"Root Beer Ale"},{"ID":2,"HasTasted":false,"Name":"Dragons Breath"},{"ID":3,"HasTasted":false,"Name":"ScAles"},{"ID":4,"HasTasted":true,"Name":"Dragons Breath"}]
Which I believe is the reason it's not rendering on my ng-repeat model.
<p>{{model | json}}</p>
<table class="table">
<tr ng-repeat="beer in model.Beers">
Is there other ways to use ng-repeat or possibly change db.Beers.ToList() to something else that will give me a model name?
BeerCtrl.js
angular.module('AngularDemo.BeerController', [])
.controller('BeerCtrl', [
'$scope', '$http', function ($scope, $http) {
$scope.model = {};
$http.get('/Beers/IndexVM').success(function (data) {
$scope.model = data;
});
}]);
return Json(new {Beers = db.Beers.ToList()}, JsonRequestBehavior.AllowGet);gives you a name for your json object.. but not sure if that's all you're missingBeerobjects is the model. I would think you'd just be able to writeng-repeat="beer in model".<tr ng-repeat="beer in model">Is the data displayed in that case?