public ActionResult GetMenuNodeList() { string fucId = Request.Params[0].Trim(); string userId = HttpContext.Session["User"].ToString(); MenuNodeList nodeList = new MenuNodeList(userId); MenuNode root = nodeList.GetCurrentRootNode(fucId); IList <MenuNodeDTO> result = new List <MenuNodeDTO>(); foreach (MenuNode child in root.Children) { MenuNodeDTO dto = new MenuNodeDTO(); dto.id = child.ID; dto.text = child.Name; dto.url = child.Url; dto.leaf = true; if (child.Children.Count > 0) { dto.leaf = false; dto.childNodes = new List <MenuNodeDTO>(); AddToRoot(child, dto.childNodes); } result.Add(dto); } return(this.Json(result)); }
public void AddToRoot(MenuNode parent, List <MenuNodeDTO> dtoList) { int i = 0; foreach (MenuNode child in parent.Children) { MenuNodeDTO dto = new MenuNodeDTO(); dto.id = child.ID; dto.text = child.Name; dto.url = child.Url; dto.leaf = true; if (child.Children.Count > 0) { dto.leaf = false; dto.childNodes = new List <MenuNodeDTO>(); AddToRoot(child, dto.childNodes); } dtoList.Add(dto); i++; } }