private static void BuildChildMenu(HtmlHelper html, NamedRoute route, TagBuilder li) { // convert menu entry to dropdown li.AddCssClass("dropdown"); li.InnerHtml = "<a href=\"#\" class=\"dropdown-toggle\" data-toggle=\"dropdown\">" + route.DisplayName + "<b class=\"caret\"></b></a>"; // build LIs for the children var ul = new TagBuilder("ul"); ul.AddCssClass("dropdown-menu"); foreach (var child in route.Children) { var childLi = new TagBuilder("li"); childLi.InnerHtml = html.RouteLink(child.DisplayName, child.Name).ToString(); ul.InnerHtml += childLi.ToString(); // support for drop down list breaks if (child.Options.HasBreakAfter) { var breakLi = new TagBuilder("li"); breakLi.AddCssClass("divider"); ul.InnerHtml += breakLi.ToString(); } } // append the UL li.InnerHtml = "<a href='#' class='dropdown-toggle' data-toggle='dropdown'>" + route.DisplayName + " <b class='caret'></b></a>" + ul.ToString(); }
public static MvcHtmlString NavigationListItemRouteLink(this HtmlHelper html, NamedRoute route) { var li = new TagBuilder("li"); li.InnerHtml = html.RouteLink(route.DisplayName, route.Name).ToString(); if (CurrentRouteMatchesName(html, route.Name)) { li.AddCssClass("active"); } if (route.Children.Any()) { BuildChildMenu(html, route, li); } // collect our html var tagBuilders = new List<TagBuilder>(); tagBuilders.Add(li); if (route.ShouldBreakAfter) { var breakLi = new TagBuilder("li"); breakLi.AddCssClass("divider-vertical"); tagBuilders.Add(breakLi); } var tags = new StringBuilder(); tagBuilders.ForEach(b => tags.Append(b.ToString(TagRenderMode.Normal))); return MvcHtmlString.Create(tags.ToString()); }
public static void MapNavigationRoute(this RouteCollection routes, string name, string url, object defaults, object constraints = null) { var newRoute = new NamedRoute(name, url, new MvcRouteHandler()) {Defaults = new RouteValueDictionary(defaults), Constraints = new RouteValueDictionary(constraints)}; routes.Add(name, newRoute); }
public static NavigationRouteBuilder MapNavigationRoute <T>(this RouteCollection routes, string displayName, Expression <Func <T, ActionResult> > action) where T : IController { var newRoute = new NamedRoute("", "", new MvcRouteHandler()); newRoute.ToDefaultAction(action); newRoute.DisplayName = displayName; routes.Add(newRoute.Name, newRoute); return(new NavigationRouteBuilder(routes, newRoute)); }
public static void MapNavigationRoute(this RouteCollection routes, string name, string url, object defaults, object constraints = null) { var newRoute = new NamedRoute(name, url, new MvcRouteHandler()) { Defaults = new RouteValueDictionary(defaults), Constraints = new RouteValueDictionary(constraints) }; routes.Add(name, newRoute); }
public static NavigationRouteBuilder AddChildRoute <T>(this NavigationRouteBuilder builder, string DisplayText, Expression <Func <T, ActionResult> > action) where T : IController { var childRoute = new NamedRoute("", "", new MvcRouteHandler()); childRoute.ToDefaultAction <T>(action); childRoute.DisplayName = DisplayText; builder._parent.Children.Add(childRoute); builder._routes.Add(childRoute.Name, childRoute); return(builder); }
public static NavigationRouteBuilder MapNavigationRoute <T>(this RouteCollection routes, string displayName, Expression <Func <T, ActionResult> > action) where T : IController { var newRoute = new NamedRoute("", "", new MvcRouteHandler()); newRoute.ToDefaultAction(action); //newRoute.Constraints = new RouteValueDictionary(new { @namespace=typeof(T).Namespace}); newRoute.DisplayName = displayName; routes.Add(newRoute.Name, newRoute); return(new NavigationRouteBuilder(routes, newRoute)); }
public static NavigationRouteBuilder MapNavigationRoute(this RouteCollection routes, string name, string displayName, string url, object defaults, bool includedInNav = false, object constraints = null) { var newRoute = new NamedRoute(name, displayName, url, new MvcRouteHandler()) { Defaults = new RouteValueDictionary(defaults), Constraints = new RouteValueDictionary(constraints), IncludedInNav = includedInNav }; routes.Add(name, newRoute); return(new NavigationRouteBuilder(routes, newRoute)); }
public static NamedRoute ToDefaultAction <T>(this NamedRoute route, Expression <Func <T, ActionResult> > action) where T : IController { var body = action.Body as MethodCallExpression; if (body == null) { throw new ArgumentException("Expression must be a method call"); } if (body.Object != action.Parameters[0]) { throw new ArgumentException("Method call must target lambda argument"); } string actionName = body.Method.Name; // check for ActionName attribute var attributes = body.Method.GetCustomAttributes(typeof(ActionNameAttribute), false); if (attributes.Length > 0) { var actionNameAttr = (ActionNameAttribute)attributes[0]; actionName = actionNameAttr.Name; } string controllerName = typeof(T).Name; if (controllerName.EndsWith("Controller", StringComparison.OrdinalIgnoreCase)) { controllerName = controllerName.Remove(controllerName.Length - 10, 10); } ; route.Defaults = LinkBuilder.BuildParameterValuesFromExpression(body) ?? new RouteValueDictionary(); foreach (var pair in route.Defaults.Where(x => x.Value == null).ToList()) { route.Defaults.Remove(pair.Key); } route.Defaults.Add("controller", controllerName); route.Defaults.Add("action", actionName); route.Url = CreateUrl(actionName, controllerName); route.Name = "Navigation-" + controllerName + "-" + actionName; if (route.DataTokens == null) { route.DataTokens = new RouteValueDictionary(); } route.DataTokens.Add("Namespaces", new string[] { typeof(T).Namespace }); return(route); }
public static NavigationRouteBuilder AddChildRoute <T>(this NavigationRouteBuilder builder, string DisplayText, Expression <Func <T, ActionResult> > action, bool includedInNav = false, string areaName = "") where T : IController { var childRoute = new NamedRoute("", "", new MvcRouteHandler()); childRoute.ToDefaultAction <T>(action, areaName); childRoute.DisplayName = DisplayText; childRoute.IsChild = true; childRoute.IncludedInNav = includedInNav; builder._parent.Children.Add(childRoute); builder._routes.Add(childRoute.Name, childRoute); return(builder); }
public static MvcHtmlString NavigationListItemRouteLink(this HtmlHelper html, NamedRoute route) { var li = new TagBuilder("li") { InnerHtml = html.RouteLink(route.DisplayName, route.Name).ToString() }; if (CurrentRouteMatchesName(html, route.Name)) { li.AddCssClass("active"); } if (route.Children.Count() > 0) { //TODO: create a UL of child routes here. } return MvcHtmlString.Create(li.ToString(TagRenderMode.Normal)); }
public static void MapNavigationRoute(this RouteCollection routes, string name, string displayName, string url, object defaults, string[] namespaces, object constraints = null) { var newRoute = new NamedRoute(name, displayName, url, new MvcRouteHandler()) { Defaults = new RouteValueDictionary(defaults), Constraints = new RouteValueDictionary(constraints), DataTokens = new RouteValueDictionary() }; if (namespaces != null && namespaces.Length > 0) { newRoute.DataTokens["Namespaces"] = namespaces; } routes.Add(name, newRoute); }
public static MvcHtmlString NavigationListItemRouteLink(this HtmlHelper html, NamedRoute route) { var li = new TagBuilder("li") { InnerHtml = html.RouteLink(route.DisplayName, route.Name).ToString() }; if (CurrentRouteMatchesName(html, route.Name)) { li.AddCssClass("active"); } if (route.Children.Count() > 0) { //TODO: create a UL of child routes here. li.AddCssClass("dropdown"); li.InnerHtml = "<a href=\"#\" class=\"dropdown-toggle\" data-toggle=\"dropdown\">" + route.DisplayName + "<b class=\"caret\"></b></a>"; var ul = new TagBuilder("ul"); ul.AddCssClass("dropdown-menu"); foreach (var child in route.Children) { var childLi = new TagBuilder("li"); childLi.InnerHtml = html.RouteLink(child.DisplayName, child.Name).ToString(); ul.InnerHtml += childLi.ToString(); } //that would mean we need to make some quick li.InnerHtml = "<a href='#' class='dropdown-toggle' data-toggle='dropdown'>" + route.DisplayName + " <b class='caret'></b></a>" + ul.ToString(); } return(MvcHtmlString.Create(li.ToString(TagRenderMode.Normal))); }
public NavigationRouteBuilder(RouteCollection routes, NamedRoute parent) { _routes = routes; _parent = parent; }
private static void BuildChildMenu(HtmlHelper html, NamedRoute route, TagBuilder li) { // convert menu entry to dropdown li.AddCssClass("dropdown"); li.InnerHtml = "<a href=\"#\" class=\"dropdown-toggle\" data-toggle=\"dropdown\">" + route.DisplayName + "<b class=\"caret\"></b></a>"; // build LIs for the children var ul = new TagBuilder("ul"); ul.AddCssClass("dropdown-menu"); foreach (var child in route.Children) { var childLi = new TagBuilder("li"); childLi.InnerHtml = html.RouteLink(child.DisplayName, child.Name).ToString(); ul.InnerHtml += childLi.ToString(); // support for drop down list breaks if (child.ShouldBreakAfter) { var breakLi = new TagBuilder("li"); breakLi.AddCssClass("divider"); ul.InnerHtml += breakLi.ToString(); } } // append the UL li.InnerHtml = "<a href='#' class='dropdown-toggle' data-toggle='dropdown'>" + route.DisplayName + " <b class='caret'></b></a>" + ul.ToString(); }
public static MvcHtmlString NavigationListItemRouteLink(this HtmlHelper html, NamedRoute route) { var li = new TagBuilder("li") { InnerHtml = html.RouteLink(route.DisplayName, route.Name).ToString() }; if (CurrentRouteMatchesName(html, route.Name)) { li.AddCssClass("active"); } if (route.Children.Count() > 0) { //TODO: create a UL of child routes here. } return(MvcHtmlString.Create(li.ToString(TagRenderMode.Normal))); }
public static MvcHtmlString NavigationListItemRouteLink(this HtmlHelper html, NamedRoute route) { var li = new TagBuilder("li") { InnerHtml = html.RouteLink(route.DisplayName, route.Name).ToString() }; if (CurrentRouteMatchesName(html, route.Name)) { li.AddCssClass("active"); } if (route.Children.Count() > 0) { //TODO: create a UL of child routes here. li.AddCssClass("dropdown"); li.InnerHtml = "<a href=\"#\" class=\"dropdown-toggle\" data-toggle=\"dropdown\">" + route.DisplayName +"<b class=\"caret\"></b></a>"; var ul = new TagBuilder("ul"); ul.AddCssClass("dropdown-menu"); foreach (var child in route.Children) { var childLi = new TagBuilder("li"); childLi.InnerHtml = html.RouteLink(child.DisplayName, child.Name).ToString(); ul.InnerHtml += childLi.ToString(); } //that would mean we need to make some quick li.InnerHtml = "<a href='#' class='dropdown-toggle' data-toggle='dropdown'>"+route.DisplayName + " <b class='caret'></b></a>" + ul.ToString(); } return MvcHtmlString.Create(li.ToString(TagRenderMode.Normal)); }