public IEnumerable <MvcSiteMapNode> GetBreadcrumb(ViewContext context) { String area = context.RouteData.Values["area"] as String; String action = context.RouteData.Values["action"] as String; String controller = context.RouteData.Values["controller"] as String; MvcSiteMapNode current = AllNodes.SingleOrDefault(node => String.Equals(node.Area, area, StringComparison.OrdinalIgnoreCase) && String.Equals(node.Action, action, StringComparison.OrdinalIgnoreCase) && String.Equals(node.Controller, controller, StringComparison.OrdinalIgnoreCase)); List <MvcSiteMapNode> breadcrumb = new List <MvcSiteMapNode>(); while (current != null) { breadcrumb.Insert(0, new MvcSiteMapNode { IconClass = current.IconClass, Controller = current.Controller, Action = current.Action, Area = current.Area }); current = current.Parent; } return(breadcrumb); }
private IEnumerable <MvcSiteMapNode> CopyAndSetState(IEnumerable <MvcSiteMapNode> nodes, String area, String controller, String action) { List <MvcSiteMapNode> copies = new List <MvcSiteMapNode>(); foreach (MvcSiteMapNode node in nodes) { MvcSiteMapNode copy = new MvcSiteMapNode(); copy.IconClass = node.IconClass; copy.IsMenu = node.IsMenu; copy.Controller = node.Controller; copy.Action = node.Action; copy.Area = node.Area; copy.Children = CopyAndSetState(node.Children, area, controller, action); copy.HasActiveChildren = copy.Children.Any(child => child.IsActive || child.HasActiveChildren); copy.IsActive = copy.Children.Any(child => child.IsActive && !child.IsMenu) || ( String.Equals(node.Area, area, StringComparison.OrdinalIgnoreCase) && String.Equals(node.Action, action, StringComparison.OrdinalIgnoreCase) && String.Equals(node.Controller, controller, StringComparison.OrdinalIgnoreCase) ); copies.Add(copy); } return(copies); }
private IEnumerable <MvcSiteMapNode> GetNodes(XElement siteMap, MvcSiteMapNode parent) { List <MvcSiteMapNode> nodes = new List <MvcSiteMapNode>(); foreach (XElement element in siteMap.Elements("siteMapNode")) { MvcSiteMapNode node = new MvcSiteMapNode(); node.IsMenu = (Boolean?)element.Attribute("menu") == true; node.Controller = (String)element.Attribute("controller"); node.IconClass = (String)element.Attribute("icon"); node.Action = (String)element.Attribute("action"); node.Area = (String)element.Attribute("area"); node.Children = GetNodes(element, node); node.Parent = parent; nodes.Add(node); } return(nodes); }
private Boolean IsEmpty(MvcSiteMapNode node) { return(node.Action == null && !node.Children.Any()); }