ASPForums.Net RSS Feed additions to the content that appears on ASPForums.Net(c) 2019 All rights reserved.JsonResult Error: A circular reference was detected while serializing an object of type in ASP.Net MVC with AngularJS<p>Hi&nbsp;rani,</p> <p>To&nbsp;avoid the error create&nbsp;a ViewModel which is identical to your structure or with required properties and&nbsp;pass the ViewModel to return JsonResult.</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">Database</span></strong></p> <p>For this example I have used of Northwind database that you can download using the link given below.</p> <p><a href="" target="_blank">Download Northwind Database</a></p> <p><strong><span style="text-decoration: underline;">Model</span></strong></p> <pre class="brush: csharp">public class EmployeeModel { public int EmployeeID { get; set; } public string Name { get; set; } public string Country { get; set; } }</pre> <p><strong><span style="text-decoration: underline;">Controller</span></strong></p> <pre class="brush: csharp">public class HomeController : Controller { // GET: /Home/ public ActionResult Index() { return View(); } public JsonResult GetEmployees() { NorthwindEntities entities = new NorthwindEntities(); var employees = entities.Employees.Select(x =&gt; new EmployeeModel { EmployeeID = x.EmployeeID, Name = x.FirstName + &#34; &#34; + x.LastName, Country = x.Country }).ToList(); return Json(employees, JsonRequestBehavior.AllowGet); } }</pre> <p><strong><span style="text-decoration: underline;">View</span></strong></p> <pre class="brush: html">&lt;html&gt; &lt;head&gt; &lt;title&gt;Index&lt;/title&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; var app = angular.module(&#39;MyApp&#39;, []) app.controller(&#39;MyController&#39;, function ($scope, $http, $window) { $scope.Employees = []; $http({ method: &#39;Get&#39;, url: &#39;/Home/GetEmployees/&#39; }).success(function (response) { $scope.Employees = response; }).error(function (response) { $window.alert(response); }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div ng-app=&#34;MyApp&#34; ng-controller=&#34;MyController&#34;&gt; &lt;table&gt; &lt;tr&gt; &lt;th&gt;Id&lt;/th&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Country&lt;/th&gt; &lt;/tr&gt; &lt;tbody ng-repeat=&#34;employee in Employees&#34;&gt; &lt;tr&gt; &lt;td&gt;{{employee.EmployeeID}}&lt;/td&gt; &lt;td&gt;{{employee.Name}}&lt;/td&gt; &lt;td&gt;{{employee.Country}}&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt;</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><strong><span style="text-decoration: underline;"><img src="" alt="" width="250" height="367" /></span></strong></p>, 18 Jun 2019 01:19:11 GMT