I would like to create menu from the items stored in the database, instead of hardwiring them in AppNavigationProvider.cs. Do you have a sample example for this purpose? What should be the database look like for this purpose and in what format menus should be returned to abp.nav.menus.MainMenu?
I am using ANZ v8 MVC Core and Jquery.
11 Answer(s)
-
0
This is inconsistent with the design of the framework, You may need to change a lot of framework built-in components.The menu may depend on permissions or features.
If you only want to create some dynamic menus, you can add it to the current function, read these menus from the database, and display them in the UI, so that it will not change the design of the framework.
-
0
Do you mean I should get menu from database in
SetNavigation
function ofAppNavigationProvider1
as shown below?public override void SetNavigation(INavigationProviderContext context) { var menu = context.Manager.Menus[MenuName] = new MenuDefinition(MenuName, new FixedLocalizableString("Main Menu")); var myList = _myMenuService.GetMenusByMyParameter(_mySession.myParameter); foreach(MyMenuItem myMenuItem in myList) { menu.AddItem(new MenuItemDefinition( myMenuItem.Text, L(myMenuItem.Text), url: myMenuItem.url, icon: myMenuItem.icons, permissionDependency: new SimplePermissionDependency(myMenuItem.permissionString) ) } }
-
0
XXXNavigationProvider
will only read the menu when the application starts, if this is what you need you can read the database in theSetNavigation
method. -
0
Do we have access to AbpSession.UserId in SetNavigation method?
Yes, I just need to get the menu from the database and display them with any permission dependcies as well. Is this a suitable placce?
-
0
NavigationProvider
will be initialized when the application starts. Although you can injectIAbpSession
, it may have no value. -
0
So what would be the best place to read menu from the database? I would need a value from session to retreive menu from the database. You mentioned current function in previous reply where is this function? Please reply comprehensively if possible with example so that I can close this ticket quickly. Thanks
-
0
You can combine Abp's menu(
_userNavigationManager.GetMenuAsync
) with your dynamic menu inView
.It's easiest to get extra menus this way.
-
0
Are you referring to following code in
AppMenuViewComponent
var model = new MenuViewModel { Menu = await _userNavigationManager.GetMenuAsync(AppNavigationProvider.MenuName, _abpSession.ToUserIdentifier()), CurrentPageName = currentPageName };
How will the menu order be handled? Can I recreate Abp's menu in my database and then just get all menu from the database instead of getting Abp's from navigationManager and then appending mine from the database?
-
0
Yes, and
HeaderViewComponent
.You cannot change the design of ABP. Of course you can design your own menu system. Read the menu from the database.
How will the menu order be handled?
https://github.com/aspnetzero/aspnet-zero-core/issues/3013
-
0
I am unable to access following link, I am logged in with my credentials to aspnetzero support. https://github.com/aspnetzero/aspnet-zero-core/issues/3013
-
0
Hi,
You need to add your GitHub user on https://aspnetzero.com/LicenseManagement.