简体   繁体   中英

Razor Pages - reusable components?

Is it possible to have components for reusable items?

Example 1: a menu is always displayed on every page,

  • If account active is "business" display business menu items.
  • If account active is "personal" display personal menu items.

Example 2: Notifications are displayed on every page and a new notification will trigger a red badge counter next to the notification icon.

Yes you can have a reusable items and this is the benefit of the partial view which can be impeded at the main view. however if you are asking about displaying menu in each page based on the role of the user you should do the following:

  1. Create partial view for the business menu and another one for the personal menu.

  2. Render both the partial views at the main layout of your application.

  3. Add condition at the razor view "layout" based on the role of the user for displaying the menu (ie, if the role of the user Admin display the business menu else display the personal menu).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM