Starts in:
1 DAY
16 HRS
31 MIN
5 SEC
Starts in:
1 D
16 H
31 M
5 S

Lepton - Implementation of MenuItemName #10562


Example & Test

I've a page with route /products/{Name}/{Model}, and that page sets the MenuItemName as Products

    protected override Task OnInitializedAsync()
    {
        PageLayout.MenuItemName = MenuProducts;
        return base.OnInitializedAsync();
    }

image


Setup

And also selected menu items can be changed at runtime.

  • Menu Contributor

    context.Menu.Items.Insert(
                1,
                new ApplicationMenuItem(
                    "MyProjectName.Products",
                    "Products",
                    "/products",
                    icon: "fas fa-circle"
                ));
            context.Menu.Items.Insert(
                1,
                new ApplicationMenuItem(
                    "MyProjectName.A",
                    "Menu A",
                    "#a",
                    icon: "fas fa-square"
                ));
            context.Menu.Items.Insert(
                1,
                new ApplicationMenuItem(
                    "MyProjectName.B",
                    "Menu B",
                    "#b",
                    icon: "fas fa-plus"
                ));
    
  • Razor page:

    @page "/products/{Name}/{Model}"
    
    @inject Volo.Abp.AspNetCore.Components.Web.Theming.Layout.PageLayout PageLayout
    
    <h1>Products Page</h1>
    
    
    <ul>
        <li><b>Name: </b> @Name</li>
        <li><b>Model: </b> @Model</li>
    </ul>
    
    <Button Clicked="(()=> ChangeMenu(MenuProducts))">Change Menu (Products) </Button>
    <Button Clicked="(()=> ChangeMenu(MenuA))">Change Menu (A) </Button>
    <Button Clicked="()=>ChangeMenu(MenuB)">Change Menu (B) </Button>
    
  • And the class:

    public partial class ProductsPage
    {
    [Parameter] public string Name { get; set; }
    [Parameter] public string Model { get; set; }
    
    const string MenuProducts = "MyProjectName.Products";
    const string MenuA = "MyProjectName.A";
    const string MenuB = "MyProjectName.B";
    
    protected override Task OnInitializedAsync()
    {
         PageLayout.MenuItemName = MenuProducts;
         return base.OnInitializedAsync();
    }
    
    protected void ChangeMenu(string menuName)
    {
         Console.WriteLine("ChangeMenu: " + menuName);
         PageLayout.MenuItemName = menuName;
    }
    }
    

The Result

menuitemname

Version
6.0.0
Release Date
05 October, 2022
Labels
feature lepton-theme