How to pass json data from C# controller to angular js ? I want to pass json from controller to angular js. I tried different but none of them worked. See my code below,
var app = angular.module('myApp', []);
app.controller('customersCtrl', function ($scope, $http) {
$http.get("/adnActions/getJson")
.success(function (response) { alert(response.records); $scope.names = response.records; });
});
C# controller code
public async Task<string> getJson()
{
data="{'records':[ {'Name':'Alfreds Futterkiste','City':'Berlin','Country':'Germany'}, {'Name':'Ana Trujillo Emparedados y helados','City':'México D.F.','Country':'Mexico'}]}";
return data;
}
but am unable to get the data in angular js controller below is the error raised in console, "Error: JSON.parse: expected property name or '}' at line 1 column 2 of the JSON data
how to fix this? Whats the problem here?