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的模板模板使用本系统创建和显示菜单的用户。尝试创建一个模板并查看更多的源代码。

ABP框架系列之三十七:(Navigation-导航)的更多相关文章

  1. ABP框架系列之三十四:(Multi-Tenancy-多租户)

    What Is Multi Tenancy? "Software Multitenancy refers to a software architecture in which a sing ...

  2. ABP框架系列之三十九:(NLayer-Architecture-多层架构)

    Introduction Layering of an application's codebase is a widely accepted technique to help reduce com ...

  3. ABP框架系列之十七:(Data-Filters-数据过滤)

    Introduction It's common to use the soft-deletepattern which is used to not delete an entity from da ...

  4. ABP框架系列之三十三:(Module-System-模块系统)

    Introduction ASP.NET Boilerplate provides an infrastructure to build modules and compose them to cre ...

  5. ABP框架系列之三:(Entity Framework Integration-实体框架集成)

    ASP.NET Boilerplate can work with any O/RM framework. It has built-in integration with EntityFramewo ...

  6. ABP框架系列之三十八:(NHibernate-Integration-NHibernate-集成)

    ASP.NET Boilerplate can work with any O/RM framework. It has built-in integration with NHibernate. T ...

  7. ABP框架系列之三十二:(Logging-登录)

    Server Side(服务端) ASP.NET Boilerplate uses Castle Windsor's logging facility. It can work with differ ...

  8. ABP框架系列之三十五:(MVC-Controllers-MVC控制器)

    Introduction ASP.NET Boilerplate is integrated to ASP.NET MVC Controllers via Abp.Web.Mvc nuget pack ...

  9. ABP框架系列之三十六:(MVC-Views-MVC视图)

    Introduction ASP.NET Boilerplate is integrated to MVC Views via Abp.Web.Mvc nuget package. You can c ...

随机推荐

  1. 使用 JavaScript 将 XML 转成 JSON

    function xmlToJson(xml) { // Create the return object var obj = {}; if (xml.nodeType == 1) { // elem ...

  2. udev example -- detect usb and write test file

    之前学习了下Udev,就随便做了个测试小程序.....设计什么的也没考虑,就实现了一个基本功能,插入U盘,识别,循环检测到有特定文件后,就然后往U盘里面写数据,插拔多次,都能正常工作. 里面的warn ...

  3. 内训--PPT演示技巧

    企业内训,实操,不涉及如何做PPT,仅讲解PPT播放等内容.做好PPT后,在演讲的过程中,如何使用这些功能.

  4. python中建模分析零息票收益率曲线--复利和连续复利

    收益率曲线(Yield Curve)是显示一组货币和信贷风险均相同,但期限不同的债券或其他金融工具收益率的图表.纵轴代表收益率,横轴则是距离到期的时间.在此用python建模分析零息票收益率曲线,输出 ...

  5. MySQL学习笔记Windows篇<一> Welcome to MySQL

    MySQL安装完毕后没有图形化操作界面,图形化管理界面需要另行安装,个人比较喜欢Navicat,界面更像SQLserver: 此篇学习笔记所有操作均使用命令行中完成: 1.开启/停止服务 使用MySQ ...

  6. Android 开发 VectorDrawable 矢量图 (二)了解矢量图属性与绘制

    VectorDrawable 矢量图 三部曲: Android 开发 VectorDrawable 矢量图 (一)了解Android矢量图与获取矢量图 Android 开发 VectorDrawabl ...

  7. lambda表达式,filter,map,reduce,curry,打包与解包和

    当然是函数式那一套黑魔法啦,且听我细细道来. lambda表达式 也就是匿名函数. 用法:lambda 参数列表 : 返回值 例: +1函数 f=lambda x:x+1 max函数(条件语句的写法如 ...

  8. TP5.1 钩子与行为应用

    什么是行为: 可以将行为理解为是一个行为类的方法,在框架中行为类.行为方法则是有一定的规则约定:而钩子则是这些行为方法被调用执行的位置点.注意了,要想执行某个钩子中的行为,那行为一定要在应用程序执行到 ...

  9. CSS样式学习-3、轮廓、伪类/元素、display-flex布局

    一.轮廓 outline绘制于元素周围的一条线,位于边框边缘外围. 属性规定元素轮廓的样式.颜色.宽度. outline-width轮廓宽度,属性:thin细轮廓.medium中等(默认值).thic ...

  10. python中的异常处理常用方法

    异常处理 什么是异常? 异常就是与正常情况不同,程序在执行过程中出现错误,导致无法执行完毕.异常其实就是代码执行过程中出错. 常见的一些异常 AttributeError 试图访问一个对象没有的属性, ...