How to configure dynamicaly added menu item

Topics: Administration, General
Mar 3, 2015 at 11:33 AM
Hello everyone,

I have programmatically added a main menu item as shown below.
public class MainMenu : IMenuProvider
        public Localizer T { get; set; }
        private readonly IContentManager _contentManager;
        public MainMenu(IContentManager contentManager)
            _contentManager = contentManager;
        public void GetMenu(IContent menu, NavigationBuilder builder)
            builder.Add(T("OUR SERVICES"), "1", item => item.Url("~/OurServices"));
            builder.Add(T("WORKPLACE SUPPORT"), "2", item => item.Url("~/WorkplaceSupport"));
            builder.Add(T("WHAT PEOPLE SAY"), "3", item => item.Url("~/WhatPeopleSay"));
            builder.Add(T("ABOUT US"), "4", item => item.Url("~/AboutUs"));
            builder.Add(T("CONTACT US"), "5", item => item.Url("~/ContactUs"));

What steps do I need to take to make this menu item appear in Dashboard > Navigation link
Mar 3, 2015 at 8:00 PM

If you want to add a custom set of menu items to the admin dashboard you need to implement inavigationprovider


Mar 4, 2015 at 3:48 AM
Edited Mar 4, 2015 at 3:59 AM
Hi, Thanks for the reply

I don't want to add it in the Dashboard admin as a separate menu. What I want is I should be able to edit this menu item through Dashboard > Navigation link

My menu appears on the home page but i cant edit it from dashboard like home link. so my question is What steps do I need to take to make this menu item appear in Dashboard > Navigation link like HOME
Mar 4, 2015 at 7:59 AM
Edited Mar 4, 2015 at 8:02 AM
You are hardcoding your menu in MainMenu.cs. Therefore you are not able to see it in the Dashboard -> Navigation.

Instead of hardcoding your main menu, add the needed links through the Dashboard/navigation to your main menu. This way you have control over the items in your dashboard.

If you don't want to do this manually, but want to be able to have control over it, put it in the <Command> section of a recipe:

menuitem create /MenuPosition:"0" /MenuText:"Home" /Url:"~/" /MenuName:"Main Menu"
Mar 4, 2015 at 10:05 AM
Edited Mar 4, 2015 at 10:19 AM
Thanks its really helpful. But cant we added this via code the way it is done via dashboard
Mar 4, 2015 at 12:34 PM
Edited Mar 4, 2015 at 12:47 PM
Yes you can do it also through Migrations (I guess)
Mar 5, 2015 at 5:38 AM
Can you show some code