Open Closed

Add Sub Menu Item to the Admin section #1952


User avatar
0

Hi,

I am trying to add a menu item to the ApplicationMenuItem . In the MenuContributor.cs class, the following code returns the list of menu items: var administration = context.Menu.GetAdministration();

Is it possible to extend the ApplicationMenuItem, and add a new Menu item under Admin tab, from the module I created? Or do I have to download the volo module for Admin Menu items and add it there?

Any help would be appreciated.

Thanks,

Jesse

  • ABP Framework version: latest
  • UI type: Blazor
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no

6 Answer(s)
  • User Avatar
    0
    enisn created
    Support Team .NET Developer

    Hi, Do you ask creating your own section like below?

    var administration = context.Menu.GetAdministration();
    
    var mySection = new ApplicationMenuItem("MySection", "My Section", "#", "fa fa-file");
    
    administration.AddItem(mySection);
    
    mySection.AddItem(new ApplicationMenuItem("MySubMenu", "My Sub Menu 1", "#"));
    mySection.AddItem(new ApplicationMenuItem("MySubMenu2", "My Sub Menu 2", "#"));
    mySection.AddItem(new ApplicationMenuItem("MySubMenu3", "My Sub Menu 3", "#"));
    
    var mySubMenu4 = new ApplicationMenuItem("MySubMenu4", "My Sub Menu 4", "#");
    
    mySubMenu4.AddItem(new ApplicationMenuItem("MySubMenu4A", "My Sub Menu 4.A", "#"));
    mySubMenu4.AddItem(new ApplicationMenuItem("MySubMenu4B", "My Sub Menu 4.B", "#"));
    
    mySection.AddItem(mySubMenu4);
    
  • User Avatar
    1
    enisn created
    Support Team .NET Developer

    Or you can add your custom menu under existing module menu:

    var administration = context.Menu.GetAdministration();
    
    var languagesMenu = administration.FindMenuItem(LanguageManagementMenuNames.GroupName);
    
    languagesMenu.AddItem(new ApplicationMenuItem("MySubLanguageMenu", "My Sub Language Menu", "#"));
    
  • User Avatar
    0

    Thank you Enisn, this worked!

  • User Avatar
    0

    Hi Enisn,

    Further to this question, how can I make the menu items I added invisible when the user is NOT logged in?

    Thanks for your help!

    Jesse

  • User Avatar
    0
    enisn created
    Support Team .NET Developer

    Hi,

    You can use .RequireAuthenticated() extension method for MenuItem:

    var administration = context.Menu.GetAdministration();
    
    var languagesMenu = administration.FindMenuItem(LanguageManagementMenuNames.GroupName);
    
    var menuItem = new ApplicationMenuItem(
                        "MySubLanguageMenu", 
                        "My Sub Language Menu", 
                        "#")
                   .RequireAuthenticated(); // <-- You add this method.
    
    languagesMenu.AddItem(menuItem);
    
  • User Avatar
    0

    Thank you very much Ensin!

    Jesse

Made with ❤️ on ABP v9.1.0-preview. Updated on December 05, 2024, 12:19