public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);

            List<Page> pages = Page.GetMenu();

            Menu mainMenu = new Menu(Display.MainMenu, filterContext.RequestContext.RouteData.Values);
            foreach (Page p in pages)
            {
                MenuItem item = new MenuItem(mainMenu, p.Title, p.Url);
                mainMenu.Items.Add(item);
            }

            filterContext.Controller.ViewBag.MainMenu = mainMenu;
        }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);

            Menu mainMenu = new Menu(Display.MainMenu, filterContext.RequestContext.RouteData.Values);

            mainMenu.Items = new List<MenuItem>()
            {
                new MenuItem(mainMenu, Display.Pages, "Index", "Pages"),
                new MenuItem(mainMenu, Display.Posts, "Index", "Posts"),
                new MenuItem(mainMenu, Display.Users, "Index", "Users"),
            };

            filterContext.Controller.ViewBag.MainMenu = mainMenu;
        }
예제 #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="htmlHelper"></param>
        /// <param name="menu"></param>
        /// <returns></returns>
        public static MvcHtmlString Breadcrumbs(this HtmlHelper htmlHelper, Menu menu, string separator = "&gt;&gt;")
        {
            MenuItem item = menu.Items.FirstOrDefault(x => x.Items, x => x.IsCurrent);
            if (item != null)
            {

                List<KeyValuePair<string, string>> crumbs = new List<KeyValuePair<string, string>>();
                UrlHelper url = new UrlHelper(htmlHelper.ViewContext.RequestContext);

                while (item != null)
                {
                    KeyValuePair<string, string> link = new KeyValuePair<string, string>(item.Title,
                        url.Action(item.Action, item.Controller, new RouteValueDictionary(item.RoutesValues)));

                    crumbs.Add(link);

                    item = item.Parent;
                }

                TagBuilder span = new TagBuilder("span");

                for (int i = crumbs.Count - 1; i >= 0; i--)
                {
                    TagBuilder linkTag = new TagBuilder("a");
                    linkTag.InnerHtml = crumbs[i].Key;
                    linkTag.MergeAttribute("title", crumbs[i].Key);
                    linkTag.MergeAttribute("href", crumbs[i].Value);

                    if (i > 0)
                    {
                        span.InnerHtml += linkTag.ToString() + "&nbsp;" + separator + "&nbsp;";
                    }
                    else
                    {
                        span.InnerHtml += linkTag.ToString();
                    }
                }

                return span.ToMvcHtmlString();
            }

            return MvcHtmlString.Empty;
        }
예제 #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="htmlHelper"></param>
        /// <param name="menu"></param>
        /// <returns></returns>
        public static MvcHtmlString Menu(this HtmlHelper htmlHelper, Menu menu, string activeItemCssClass = "active")
        {
            if (menu == null || menu.Items.Count <= 0)
                return new MvcHtmlString(string.Empty);

            TagBuilder ulTag = htmlHelper.RenderMenuItems(menu.Items);
            if (menu.HtmlAttributes != null)
            {
                RouteValueDictionary attributes = new RouteValueDictionary(menu.HtmlAttributes);
                ulTag.MergeAttributes(attributes);
            }

            return ulTag.ToMvcHtmlString();
        }
예제 #5
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="menu"></param>
 /// <param name="title"></param>
 /// <param name="action"></param>
 /// <param name="controller"></param>
 /// <param name="visible"></param>
 /// <param name="htmlAttributes"></param>
 /// <param name="routeValues"></param>
 public MenuItem(Menu menu, string title, string action, string controller, bool visible,
     object htmlAttributes, object routeValues)
     : this(menu, null, title, action, controller, visible, htmlAttributes, routeValues)
 {
 }
예제 #6
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="menu"></param>
 /// <param name="parent"></param>
 /// <param name="title"></param>
 /// <param name="action"></param>
 /// <param name="controller"></param>
 /// <param name="visible"></param>
 public MenuItem(Menu menu, MenuItem parent, string title, string action, string controller, bool visible)
     : this(menu, parent, title, action, controller, visible, null, null)
 {
 }
예제 #7
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="menu"></param>
 /// <param name="parent"></param>
 /// <param name="title"></param>
 /// <param name="action"></param>
 /// <param name="controller"></param>
 public MenuItem(Menu menu, MenuItem parent, string title, string action, string controller)
     : this(menu, parent, title, action, controller, true, null, null)
 {
 }
예제 #8
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="menu"></param>
 /// <param name="title"></param>
 /// <param name="url"></param>
 public MenuItem(Menu menu, string title, string url)
 {
     this.Menu = menu;
     this.Title = title;
     this.Url = url;
 }
예제 #9
0
 /// Creates new instance of menu item
 /// </summary>
 /// <param name="menu">Menu this itm=em is belongs to.</param>
 /// <param name="parent">Parent MenuItem of this item.</param>
 /// <param name="title">The title of menu item.</param>
 /// <param name="action">The target controller action.</param>
 /// <param name="controller">The target controller.</param>
 /// <param name="visible">Set visibility of menu item while rendering.</param>
 /// <param name="htmlAttributes">An a html attributes of the menu item.</param>
 /// <param name="routeValues">An a additional route values to specify menu item link target.</param>
 public MenuItem(Menu menu, MenuItem parent, string title, string action, string controller, bool visible,
     IDictionary<string, object> htmlAttributes, IDictionary<string, object> routeValues)
 {
     this.Menu = menu;
     this.Parent = parent;
     this.Title = title;
     this.Action = action;
     this.Controller = controller;
     this.HtmlAttributes = htmlAttributes;
     this.RoutesValues = routeValues;
     this.Visible = visible;
     this.Items = new List<MenuItem>();
 }
예제 #10
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="menu"></param>
 /// <param name="parent"></param>
 /// <param name="title"></param>
 /// <param name="action"></param>
 /// <param name="controller"></param>
 /// <param name="visible"></param>
 /// <param name="htmlAttributes"></param>
 /// <param name="routeValues"></param>
 public MenuItem(Menu menu, MenuItem parent, string title, string action, string controller, bool visible,
     object htmlAttributes, object routeValues)
     : this(menu, parent, title, action, controller, visible, null, null)
 {
     this.HtmlAttributes = htmlAttributes.ToDictionary();
     this.RoutesValues = routeValues.ToDictionary();
 }