The controller returns data, however I can't iterate over it in the HTML file. However using the expression {{phones}} directly displays the data returned. I believe the data is being returned as a string instead of json. I am expecting the names and snippets corresponding to all the data returned in the loop.
<body ng-app="phonecatApp" ng-controller="PhoneListCtrl" >
Search: <input ng-model="query">
Sort By:
<select ng-model="orderByFilter">
<option value="name">Alphabetical</option>
<option value="age">Numerical</option>
</select>
<ul>
<li ng-repeat="phone in phones | orderBy:orderByFilter">
<span>{{phone.name}}</span>
<span>{{phone.snippet}}</span>
</li>
</ul>
<script src="~/Scripts/AngularScript.js"></script>
</body>
Angular js script
var phonecatApp = angular.module('phonecatApp', []);
phonecatApp.controller('PhoneListCtrl', function ($scope, $http) {
$http.get('Home/GetJson').success(function (data){
$scope.phones = data;
});
});
Controller Action method
public JsonResult GetJson()
{
string variablename = "[{'name': 'Nexus S','snippet': 'Fast just got faster with Nexus S.', 'age': 1}]";
return Json (variablename, JsonRequestBehavior.AllowGet);
}