javascript - Serializing an object of type -
i wanted implement angularjs in mvc4. how return json in format of angular in mvc4.
here codes:
controller:
[httpget] public actionresult sample1() { return json(db.account_info.tolist(), jsonrequestbehavior.allowget); }
account.js
app.controller('account', ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) { $scope.bag = []; $scope.alldata = function () { // $http.get('/accounts/sample1').then(function ($response) { $scope.bag = $response; }); } //execute on page load $timeout(function () { $scope.alldata(); }); }]);
app.js
var app = angular.module('myapp', []);
view:
<script src="~/scripts/angular/angular.min.js"></script> <script src="~/scripts/angular/app.js"></script> <script src="~/scripts/angular/account.js"></script> <h2>sample</h2> <div ng-app="myapp" > <div ng-controller="account"> <div ng-repeat="acc in bag"> <p>username: {{acc.username}}</p> </div> </div> </div>
now, i've got error:
a circular reference detected while serializing object of type 'system.data.entity.dynamicproxies.account_info_d9c702ca15fc076225862589f60cd5e8b8ea615ef98d78a1feb764e267d88f97'.
return data controller:
need advice , help. in advance.
use .net javascript serializer so:
return new javascriptserializer().deserialize<list<account_info>>(db.account_info.tolist());
deserialize takes generic. check model type. assumed list of account_info.
Comments
Post a Comment