ABP Add dynamic Menu

Source: Internet
Author: User

The menudefinition in the ABP encapsulates the properties of the main menu on the navigation bar, and Menuitemdefinition encapsulates the properties of the submenu, which can refer to other submenus to form a menu tree.

The Menudefinitio members are as follows:

 Public ObjectCustomData {Get;Set; }//Custom Data              PublicIlocalizablestring DisplayName {Get;Set; }//represents a localized string              PublicIlist<menuitemdefinition> Items {Get;Set; }//sub-level menu collection              Public stringName {Get; }//Menu Name       PublicMenudefinition AddItem (menuitemdefinition menuItem);//submenu Add Method

The menuitemdefinition members are as follows:

 Public ObjectCustomData {Get;Set; }//Custom Data                PublicIlocalizablestring DisplayName {Get;Set; }//represents a localized string               PublicIfeaturedependency Featuredependency {Get;Set; }//Functional Characteristics                Public stringIcon {Get;Set; }//Menu Icon                Public BOOLIsLeaf {Get; }//whether there is a submenu                Public VirtualIlist<menuitemdefinition> Items {Get; }//Sub-menu               Public stringName {Get; }//Menu Name                Public intOrder {Get;Set; }//Sort                Public stringRequiredpermissionname {Get;Set; }//Permission Name                Public BOOLrequiresauthentication {Get;Set; }//permission validation is not visible if this menu is displayed by validation                Public stringURL {Get;Set; }//URL        PublicMenuitemdefinition AddItem (menuitemdefinition menuItem);//Add a sub-menu

With attributes and understanding of its role we can easily customize any menu, in general development we may need to load some dynamic menu from database, XML and other data sources to meet our system requirements, with the above objects we can easily add menu!

The Setup menu code is as follows:

  Public classAppnavigationprovider:navigationprovider { Public Override voidsetnavigation (Inavigationprovidercontext context) {#regionStatic menucontext. Manager.mainmenu. AddItem (Newmenuitemdefinition (AppPageNames.Host.Tenants, L ("Hostdashboardmenu"), URL:"Host_dashboard", Icon:"Menu-icon FA fa-home", RequiredPermissionName:PermissionNames.Pages_Host_Dashboard, order:1                    )                ); #endregion            #regionDynamic Menuvarproject=Newmenuitemdefinition (AppPageNames.Common.Project, L ("Projectmenu"), URL:"Roles", Icon:"Menu-icon FA fa-briefcase", requiredPermissionName:PermissionNames.Pages_Administration_Projects, order: 5                    ); //This simulates loading data from a database             for(inti =1; I <=Ten; i++) {Project. AddItem (NewMenuitemdefinition ("P1", L ("Project"+i), url:"Project", Icon:"Menu-icon FA fa-tasks", RequiredPermissionName:PermissionNames.Pages_Administration_Projects, C            USTOMDATA:I)); } context.            Manager.MainMenu.AddItem (project); #endregion                   }        Private StaticIlocalizablestring L (stringname) {            return Newlocalizablestring (name, datacenterconsts.localizationsourcename); }    }

The effect is as follows

ABP Add dynamic Menu

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.