I learned how to implement partial Ajax refresh paging today and encountered such an exception.
Circular references are detected when the serialization type is "ajax learning. datasetcomment + t_commentdatatable.
That is to say, because the data type is too complex, JSON cannot be converted to the data type. Now we need to store the data you want to convert in the form of class objects to solve this problem.
Today, I listed some of my code for your reference.
Pre-solution code
{
VaR adapter = new t_commenttableadapter ();
String pagenum = context. request ["pagenum"]; int ipagenum = convert. toint32 (pagenum); var DATA = adapter. getpageddata (ipagenum-1) * 10 + 1, ipagenum * 10 );
Javascriptserializer JSS = new javascriptserializer (); // serialized object in Javascript
Context. response. Write (JSS. serialize (data); // output to the page
}
Code after solution
{ var data = adapter.GetPagedData((iPageNum - 1) * 10 + 1, iPageNum * 10); List<Comments> list=new List<Comments> (); foreach(var row in data) { list.Add(new Comments() { Id = (int)row.Id, IP = row.IP, Msg = row.Msg, PostDate = row.PostDate, }); } JavaScriptSerializer jss = new JavaScriptSerializer(); context.Response.Write(jss.Serialize(list));}
Public class comments
{
Public int ID {Get; set ;}
Public String IP {Get; set ;}
Public String MSG {Get; set ;}
Public String postdate {Get; set ;}
}