public static MvcHtmlString Menu(this HtmlHelper helper, Model.SiteMap siteMap, object htmlAttributes = null) { var attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes) as IDictionary <string, object>; var tag = new TagBuilder("ul"); tag.MergeAttributes(attributes); foreach (var item in siteMap.Items) { tag.InnerHtml += RenderMenu(item); } return(MvcHtmlString.Create(tag.ToString())); }
public static HtmlString Breadcrumb(this HtmlHelper helper, Model.SiteMap siteMap) { var home = Settings.Get <string>("Root.SiteName"); var html = string.Empty; if (siteMap != null) { var currentPage = siteMap.Items.FindRecursive(s => s.IsActive); if (currentPage != null) { while (currentPage != null) { if (currentPage.IsActive) { html = string.Format("<li class='active'>{0}</li>", currentPage.Title); } else { html = string.Format("<li><a href='{0}'>{1}</a></li>", currentPage.Url, currentPage.Title) + html; } var parentId = currentPage.SiteContentParentID; currentPage = parentId.HasValue ? siteMap.Items.FindRecursive(s => s.SiteContentID == parentId) : null; } // Now, prepend the current site's root link html = string.Format("<li><a href='{0}'>{1}</a></li>", siteMap.SiteRootUrl, siteMap.SiteName) + html; // And finally, add the root most site (unless we've already hit it) if (!siteMap.SiteName.Equals(home)) { html = "<li><a href='/'>" + home + "</a></li>" + html; } } } return(new HtmlString(string.Format("<ol class='breadcrumb'>{0}</ol>", html))); }