public ActionResult Index() { List <TreeViewNode> nodes = new List <TreeViewNode>(); var dao = new UserGroupDao(); var entities = dao.GetUserGroups(); //Loop and add the Parent Nodes. foreach (UserGroup type in entities) { nodes.Add(new TreeViewNode { id = type.ID.ToString(), parent = "#", text = type.Name }); } var childEntity = dao.GetRoleByGroup(); // Loop and add the Child Nodes. foreach (UserRoleByGroupModel subType in childEntity) { nodes.Add(new TreeViewNode { id = subType.role.ID.ToString(), parent = subType.userGroup.ID.ToString(), text = subType.role.Name }); } //Serialize to JSON string. ViewBag.Json = (new JavaScriptSerializer()).Serialize(nodes); SetAlert("Load thành công", "success"); return(View()); }