Every web application has some menu to navigate between pages/screens. ASP.NET Boilerplate provides a common ifrastructure to create and show menu to users.
每個Web應用程序都有一些菜單在頁面/屏幕之間導航。ASP.NET提供了一個通用的ifrastructure樣板文件創建和顯示菜單的用戶。
Creating Menus
An application may be consists of different modules and each module can have it's own menu items. To define menu items, we need to create a class derived from NavigationProvider.
Assume that we have a main menu as shown below:
應用程序可以由不同的模塊組成,每個模塊都可以有自己的菜單項。定義菜單項,我們需要創建一個類派生navigationprovider。
假設我們有一個主菜單,如下所示:
- Tasks
- Reports
- Administration
- User management
- Role management
Here, Administration menu item has two sub menu items. Example navigation provider class to create such a menu can be as below:
public class SimpleTaskSystemNavigationProvider : NavigationProvider { public override void SetNavigation(INavigationProviderContext context) { context.Manager.MainMenu .AddItem( new MenuItemDefinition( "Tasks", new LocalizableString("Tasks", "SimpleTaskSystem"), url: "/Tasks", icon: "fa fa-tasks" ) ).AddItem( new MenuItemDefinition( "Reports", new LocalizableString("Reports", "SimpleTaskSystem"), url: "/Reports", icon: "fa fa-bar-chart" ) ).AddItem( new MenuItemDefinition( "Administration", new LocalizableString("Administration", "SimpleTaskSystem"), icon: "fa fa-cogs" ).AddItem( new MenuItemDefinition( "UserManagement", new LocalizableString("UserManagement", "SimpleTaskSystem"), url: "/Administration/Users", icon: "fa fa-users", requiredPermissionName: "SimpleTaskSystem.Permissions.UserManagement" ) ).AddItem( new MenuItemDefinition( "RoleManagement", new LocalizableString("RoleManagement", "SimpleTaskSystem"), url: "/Administration/Roles", icon: "fa fa-star", requiredPermissionName: "SimpleTaskSystem.Permissions.RoleManagement" ) ) ); } }
A MenuItemDefinition can basically have a unique name, a localizable display name, a url and an icon. Also,
一個menuitemdefinition基本上能有一個獨特的名字,一個本地化的顯示名稱,URL和圖標
- A menu item may require a permission to show this menu to a particular user (See authorization document). requiredPermissionName property can be used in this case.
- A menu item can be depend on a feature. featureDependency property can be used in this case.
- A menu item can define a customData and order.
-
菜單項可能需要允許將菜單顯示給特定用戶(請參閱授權文檔)。requiredpermissionname屬性可以在這種情況下使用。
菜單項可以依賴於一個特性。FeatureDependency屬性可以在這種情況下使用。
菜單項可以定義一個customdata和order。
INavigationProviderContext has methods to get existing menu items, add menus and menu items. Thus, different modules can add it's own items to the menu.
There may be one or more menus in an application. context.Manager.MainMenu references the default, main menu. We can create and add more menus using context.Manager.Menus property.
inavigationprovidercontext有方法讓現有的菜單項,添加菜單和菜單項。因此,不同的模塊可以將自己的項目添加到菜單中。
應用程序中可能有一個或多個菜單。context.manager.mainmenu引用默認的主菜單。我們可以創建和使用context.manager.menus屬性添加更多的菜單。
Registering Navigation Provider
After creating the navigation provider, we should register it to ASP.NET Boilerplate configuration on PreInitialize event of our module:
Configuration.Navigation.Providers.Add<SimpleTaskSystemNavigationProvider>();
Showing Menu
IUserNavigationManager can be injected and used to get menu items and show to the user. Thus, we can create menu in server side.
ASP.NET Boilerplate automatically generates a javascript API to get menu and items in client side. Methods and objects under abp.nav namespace can be used for this purpose. For instance, abp.nav.menus.MainMenucan be used to get main menu of the application. Thus, we can create menu in client side.
ASP.NET Boilerplate templates uses this system to create and show menu to the user. Try to create a template and see source codes for more.
iusernavigationmanager可以注入,用得到的菜單項和顯示給用戶。因此,我們可以在服務器端創建菜單。
ASP.NET樣板自動生成JavaScript API來獲取客戶端菜單項。在abp.nav命名空間對象和方法可用於這一目的。例如,abp.nav.menus.mainmenucan被用於獲得應用程序主菜單。因此,我們可以在客戶端創建菜單。
ASP.NET的模板模板使用本系統創建和顯示菜單的用戶。嘗試創建一個模板並查看更多的源代碼。