Error in getting the data

Jul 12, 2011 at 4:07 PM

Hi, Im having this error A circular reference was detected while serializing an object of type 'System.Data.Entity.DynamicProxies.User_03B2501051AAAE3B4B69088BBFB627DF505DA12C7FD0AA5346A080026C2C858D' when i try to display the data in grid.



Jul 12, 2011 at 4:44 PM

I need some more information about your code to give you a better answer,
but basically, the ToGridData method you use in the Controller to populate the grid will serialize your model into json (using the standard JSONSerializer).
This scenario could fail if your model has cyclic reference, e.g: Person has City, and City has Persons.

You could solve this (again I'm shooting in the dark now) by using LinQ's select new syntax to generate a flatten view for the grid.

Jul 12, 2011 at 4:48 PM

this is my controller

public ActionResult List(SearchModel searchModel)
 var tbl = new DynamicModel("eHomeHealthCareMassive", tableName: "Users", primaryKeyField: "UserID");

 List<User> list = db.Users.ToList();

 return Json(list.AsQueryable().ToGridData(searchModel, new[] { "UserID", "FirstName", "LastName", "UserName" }), JsonRequestBehavior.AllowGet);


this is my page
@Html.Grid(new GridControl()
    .AddColumn(new GridColumnModel("UserID").SetAsPrimaryKey())
    .AddColumn(new GridColumnModel("FirstName"))
    .AddColumn(new GridColumnModel("LastName"))
    .AddColumn(new GridColumnModel("UserName"))

    .UpdateDefaultPager(pager =>
            .ShowDel(true, deleteUrl: "/SysAdmin/Delete")

Jul 12, 2011 at 4:54 PM
Edited Jul 12, 2011 at 4:55 PM

The missing puzzle is your User model entity structure, but in case, this should work:

public ActionResult List(SearchModel searchModel)

var tbl = new ...;

var list = from u in db.Users
              select new {UserID=u.UserID, 

return Json(list.ToGridData(searchModel));

Jul 12, 2011 at 5:00 PM

Thanks... ^_^