I am new to angularjs(started today...) and I have an issue with passing model from c# controller to a controller of angularjs.
It seems that I have to call a get method in my angular controller, to call a c# controller from which I will get json and load it to $scope.people for further manipulations:
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function ($scope, $http) {
$http({url: "/Home/GetPersons",method: "GET"
}).success(function (data) {
$scope.people = data;
}).error(function (error) {
$scope.error = "Failed to load";
});
});
</script>
Here is my controller :
[HttpGet]
public JsonResult GetPersons()
{
using (HRMEntities db = new HRMEntities())
{
var EmployeeList = db.Employees.Where(e => e.EmployeeId >= 0).ToList();
return Json(EmployeeList, JsonRequestBehavior.AllowGet);
}
}
As a response I get error code 500;
What is wrong in the request? And could this be made in easier way? May be using my model which is sent to a view from c# controller @model List<Employee>
EmployeeListis set, it has 67 elements inside, next step is already return, after which error is shown.var myJson = Json(EmployeeList, JsonRequestBehavior.AllowGet); return myJsonDoes it succeed to create themyJsonvar?return myJsonthere still is an error.