/// <summary> /// Find the Match Second Level Menun by currentNode. /// </summary> /// <param name="helper"></param> /// <returns></returns> public static ISiteMapNode GetFirstLevelMenuByCurrentNode(this HtmlHelper helper) { ISiteMapNode currentNode = helper.MvcSiteMap().SiteMap.CurrentNode; if (currentNode == null) { return(null); } ISiteMapNode rootNode = helper.MvcSiteMap().SiteMap.RootNode; if (rootNode == null) { return(null); } if (rootNode.Equals(currentNode)) { return(null); } while (!rootNode.Equals(currentNode)) { for (int i = 0; i < rootNode.ChildNodes.Count; i++) { if (rootNode.ChildNodes[i].Equals(currentNode)) { return(currentNode); } } currentNode = currentNode.ParentNode; } return(null); }
/// <summary> /// Initializes a new instance of the <see cref="SiteMapNodeModel"/> class. /// </summary> /// <param name="node">The node.</param> /// <param name="sourceMetadata">The source metadata provided by the HtmlHelper.</param> /// <param name="maxDepth">The max depth.</param> /// <param name="drillDownToCurrent">Should the model exceed the maxDepth to reach the current node</param> /// <param name="startingNodeInChildLevel">Renders startingNode in child level if set to <c>true</c>.</param> public SiteMapNodeModel(ISiteMapNode node, IDictionary <string, object> sourceMetadata, int maxDepth, bool drillDownToCurrent, bool startingNodeInChildLevel, bool visibilityAffectsDescendants) { if (node == null) { throw new ArgumentNullException("node"); } if (sourceMetadata == null) { throw new ArgumentNullException("sourceMetadata"); } if (maxDepth < 0) { throw new ArgumentOutOfRangeException("maxDepth"); } this.node = node; this.maxDepth = maxDepth; this.startingNodeInChildLevel = startingNodeInChildLevel; this.drillDownToCurrent = drillDownToCurrent; this.SourceMetadata = sourceMetadata; Key = node.Key; Area = node.Area; Controller = node.Controller; Action = node.Action; Site = node.Site; if (string.IsNullOrEmpty(node.Site)) { Site = node.RootNode.Site; } Title = node.Title; Description = node.Description; TargetFrame = node.TargetFrame; ImageUrl = node.ImageUrl; Url = node.Url; ResolvedUrl = node.ResolvedUrl; CanonicalUrl = node.CanonicalUrl; CanonicalUrlSeo = node.CanonicalUrlSeo; MetaRobotsContent = node.GetMetaRobotsContentString(); Include = node.Include; Exclude = node.Exclude; IsCurrentNode = (node.Equals(node.SiteMap.CurrentNode)); IsInCurrentPath = node.IsInCurrentPath(); IsRootNode = (node.Equals(node.SiteMap.RootNode)); IsClickable = node.Clickable; VisibilityAffectsDescendants = visibilityAffectsDescendants; RouteValues = node.RouteValues; Attributes = node.Attributes; Order = node.Order; }