仅从控制器获取特定数据

时间:2016-04-14 09:06:35

标签: angularjs asp.net-mvc-4

我将Json字符串传递给Service Home / GetAllAttendanceData,我想在控制器中检索它。这是我的代码..

    public JsonResult GetAllAttendanceData()
    {
        var ab = (from obj in db.Attendances where obj.Id==1 select new {EmpNTLogin = obj.EmpNTLogin });
        return this.Json(ab,JsonRequestBehavior.AllowGet);
    }

## Heading ##
 angular.module('myModule', []).service("crudAJService", function ($http) {
        this.getdata = function () {
            return $http.get("Home/GetAllAttendanceData");
        };
    }).controller('myController', function ($scope, crudAJService) {
        $scope.divBook = false;
        GetAlldata();
        function GetAlldata() {
            debugger;
            var getAttendanceData = crudAJService.getdata();

            getAttendanceData.then(function (Attendances) {

                $scope.Attendancesdata = Attendances.data
                alert($scope.Attendancesdata);
            }, function () {
                alert('Error in getting book records');
            });
        }
    });

我想在alert($ scope.Attendancesdata);

中显示字符串

1 个答案:

答案 0 :(得分:0)

也许你想要的是这个:

alert(JSON.stringify($scope.Attendancesdata));