public static IEnumerable<AD_Menu> GetList(int? parentID = null) { DANNContext db = new DANNContext(); foreach (var item in db.AD_Menu .Where(x => x.Menu_ParentId == parentID) .OrderBy(x => x.MenuSort) .ToList()) { yield return item; foreach (var child in GetList(item.Menu_Id)) { yield return child; } } }
public static ASPxMenu BuildMenu(ASPxMenu menu) { DANNContext db = new DANNContext(); List<AD_Menu> menus = GetList().ToList(); for (int i = 0; i < menus.Count; i++) { AD_Menu row = menus[i]; MenuItem item = new MenuItem(); item.Name = row.Menu_Id + ""; item.Text = row.MenuText; item.NavigateUrl = DevExpressHelper.GetUrl(new { Controller = row.MenuAction, Action = "Index" }); ; item.Image.Url = row.MenuIcon; item.BeginGroup = row.MenuSeparator.HasValue ? row.MenuSeparator.Value : false; if (i == 0 || row.Menu_ParentId + "" == "") { menu.Items.Add(item); } else { GetNodes(menu.Items, row.Menu_ParentId + "", item); } } return menu; }