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:

enter image description here

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

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -