MVC4 EF refers to itself in the data table foreign key, and when converted to JSON, always prompts the error: "Serialization type is ...." A circular reference was detected when the object was ”;
Workaround:
To convert the object to be serialized to an anonymous object, remove the navigation property as follows: It would have been VAR item=db.newscolumns.find (ID), but prompted a circular reference, so rewrite it into the following form var item= Db.newsColumns.Select (x=>new {X.id,x.name,x.parentid}). Where (x=>x.id==ID).
[HttpGet] public jsonresult getdatabyid (int ID) { var Item=db.newscolumns.select (x=>new {X.id,x.name,x.parentid}). Where (x=>x.id==ID); return Json (item, jsonrequestbehavior.allowget); }
Front desk JS:
$. Get ("/adminnewscolumn/getdatabyid", {id:id}, function (data) { $ (" #cid "). Val (data[0].id); $ ("#name"). Val (data[0].name); $ ("#onename"). Val (data[0].parentid); })
Resolves a circular reference detected when JSON serializes an object in EF