Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having a list that each list item contain another list. On the time of render the column it will give me error "http://datatables.net/tn/7". I look a lot but not found any solution. Please help me to overcome by this issue.

Full Error is below
A circular reference was detected while serializing an object of type 'System.Data.Entity.DynamicProxies.tblPropertyDocument_C39281F23DAA0C224A777580A8038E1E55D91AF3EBEC9D53EF39EC1E6EAAAD0C'.


What I have tried:

Actually I have a list of objects and inside each object i have another list. When i will return data to the datatable it will generate the circular error due for the inner list items. I know why this problem occur but not get how to resolve it.
Below is my code:
JavaScript
var SelectedAllSending = AllSending1.Select(s => new OutgoingCommunicationVM()
{
dDate = s.dDate,
id = s.id,
cDescription = s.tblDDLSelect.cDescription,
cSubject = s.cSubject,
Recipients = (from t in db.tblRecipients where (t.nMessageID == s.id) orderby t.cName select t).Take(3).ToList(),
TotalRecords = totalRecords,
PageCount = GetPageCountUSPS(s.id, s.tblDDLSelect.cDescription),
EstimatedCost = GetCost(s.id, s.tblDDLSelect.cDescription)
}).ToList();

as you see in my code I have a list "SelectedAllSending" and inside this list I have another list by the name off "Recipients".

When i will return value to the datatable it will give me error. Below is my code.

return Json(new { draw = draw, recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data = SelectedAllSending }, JsonRequestBehavior.AllowGet);

object inside object gives circular error on json return. Or how i can pass list inside list in datatable.
please help me to overcome this issue.
Posted
Updated 20-Jul-17 0:43am
v3

It worked for me

3 things require for resolvingcircular reference :

1. Apply [JsonIgnore] to navigational properties

2. In global.asax

GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;

3. serialize the data

string json = JsonConvert.SerializeObject(gridDataResult.GridData, Formatting.None);
return Json(json, JsonRequestBehavior.AllowGet);
 
Share this answer
 
Thanks Satya Prakash Swain for the response.

I worked according to your suggestion, this code resolve circular reference error but also make the inner list data to null. I need the inner list data as well.

Please help!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900