/// <summary> /// Adds a conditional css class to a set of css classes if the the current controller and action match those specified /// </summary> public static string ConditionalCssClass(this HtmlHelper helper, string action, string controller, string area, string conditionalClass, params string[] regularClasses) { StringBuilder sb = new StringBuilder(); if (regularClasses != null) { sb.Append(String.Join(" ", regularClasses)); } string currentController; string currentAction; string currentArea; string currentRouteName; bool addConditional = false; MvcSiteMap.CurrentRoute(helper.ViewContext.RequestContext, out currentController, out currentAction, out currentArea, out currentRouteName); if ( (controller == null || currentController.Equals(controller, StringComparison.InvariantCultureIgnoreCase)) && (action == null || currentAction.Equals(action, StringComparison.InvariantCultureIgnoreCase)) && (currentArea ?? String.Empty).Equals((area ?? String.Empty), StringComparison.InvariantCultureIgnoreCase)) { addConditional = true; } if (addConditional) { if (sb.Length > 0) { sb.Append(' '); } sb.Append(conditionalClass); } return(sb.ToString()); }
/// <summary> /// Returns the page title element for use in the html head element. /// </summary> /// <param name="prefix">The default site title.</param> public static MvcHtmlString HeadTitle(string prefix) { string title = MvcSiteMap.Title(); if (String.IsNullOrEmpty(title)) { return(new MvcHtmlString("<title>" + prefix + "</title>")); } return(new MvcHtmlString("<title>" + prefix + " - " + title + "</title>")); }
/// <summary> /// Renders out a ul tag with all site map nodes underneath. /// </summary> public static IHtmlString SiteMapList(this HtmlHelper helper, string action, string controller, string area, string routeName, bool showRootNode, int levels, bool asLinks, bool showDescriptions) { StringBuilder sb = new StringBuilder(); MvcSiteMapNode startNode = MvcSiteMap.FindNode(action, controller, area, routeName); //render the list UrlHelper url = new UrlHelper(helper.ViewContext.RequestContext); if ((startNode.Display & MvcSiteMapDisplay.SiteMap) == MvcSiteMapDisplay.SiteMap) { SiteMapListRenderNode(url, sb, startNode, true, showRootNode, levels, 0, asLinks, showDescriptions); } return(MvcHtmlString.Create(sb.ToString())); }