Menu

March 25, 2026 · View on GitHub

The Menu component is meant to emulate the asp:Menu control in markup and is defined in the System.Web.UI.WebControls.Menu class

Usage Notes | Syntax Comparison | Examples

Features supported in Blazor

  • Simple static menu, as shown in the ASP.NET example
  • Simple databinding to a Sitemap as shown in the ASP.NET example
  • Selection and Events - MenuItemClick event, SelectedItem, SelectedValue
  • Orientation - Horizontal or Vertical layout
  • Style Sub-Components - StaticMenuItemStyle, DynamicMenuItemStyle, StaticHoverStyle, DynamicHoverStyle, DynamicSelectedStyle, DynamicMenuStyle
  • Navigation Properties - Target, MaximumDynamicDisplayLevels, SkipLinkText
Back to top

Usage Notes

  • Databinding only works with sitemap. Sitemap must be loaded and set as an XML document on DataSource
Back to top

Syntax Comparison

=== "Web Forms"

```html
<asp:Menu
    AccessKey="string"
    BackColor="color name|#dddddd"
    BorderColor="color name|#dddddd"
    BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|
        Inset|Outset"
    BorderWidth="size"
    CssClass="string"
    DataSource="string"
    DataSourceID="string"
    DisappearAfter="integer"
    DynamicBottomSeparatorImageUrl="uri"
    DynamicEnableDefaultPopOutImage="True|False"
    DynamicHorizontalOffset="integer"
    DynamicItemFormatString="string"
    DynamicPopOutImageTextFormatString="string"
    DynamicPopOutImageUrl="uri"
    DynamicTopSeparatorImageUrl="uri"
    DynamicVerticalOffset="integer"
    Enabled="True|False"
    EnableTheming="True|False"
    EnableViewState="True|False"
    Font-Bold="True|False"
    Font-Italic="True|False"
    Font-Names="string"
    Font-Overline="True|False"
    Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|
        Large|X-Large|XX-Large"
    Font-Strikeout="True|False"
    Font-Underline="True|False"
    ForeColor="color name|#dddddd"
    Height="size"
    ID="string"
    ItemWrap="True|False"
    MaximumDynamicDisplayLevels="integer"
    OnDataBinding="DataBinding event handler"
    OnDataBound="DataBound event handler"
    OnDisposed="Disposed event handler"
    OnInit="Init event handler"
    OnLoad="Load event handler"
    OnMenuItemClick="MenuItemClick event handler"
    OnMenuItemDataBound="MenuItemDataBound event handler"
    OnPreRender="PreRender event handler"
    OnUnload="Unload event handler"
    Orientation="Horizontal|Vertical"
    PathSeparator="string"
    runat="server"
    ScrollDownImageUrl="uri"
    ScrollDownText="string"
    ScrollUpImageUrl="uri"
    ScrollUpText="string"
    SkinID="string"
    SkipLinkText="string"
    StaticBottomSeparatorImageUrl="uri"
    StaticDisplayLevels="integer"
    StaticEnableDefaultPopOutImage="True|False"
    StaticItemFormatString="string"
    StaticPopOutImageTextFormatString="string"
    StaticPopOutImageUrl="uri"
    StaticSubMenuIndent="size"
    StaticTopSeparatorImageUrl="uri"
    Style="string"
    TabIndex="integer"
    Target="string"
    ToolTip="string"
    Visible="True|False"
    Width="size" >
    <!-- DataBindings, Styles, Items, etc. -->
</asp:Menu>
```

=== "Blazor"

```razor
<Menu id="NavigationMenu"
      DisappearAfter="2000"
      StaticDisplayLevels="2"
      StaticSubmenuIndent="10"
      orientation="Vertical"
      font-names="Arial"
      target="_blank">

    <StaticMenuItemStyle BackColor="@("LightSteelBlue")"
                         ForeColor="@("Black")" />
    <StaticHoverStyle BackColor="WebColor.LightSkyBlue" />
    <DynamicMenuItemStyle BackColor="WebColor.Black"
                          ForeColor="WebColor.Silver" />
    <DynamicHoverStyle BackColor="WebColor.LightSkyBlue"
                       ForeColor="WebColor.Black" />
    <DynamicSelectedStyle BackColor="WebColor.PapayaWhip"
                          ForeColor="WebColor.SteelBlue" />

    <Items>
        <MenuItem navigateurl="Home.aspx"
                  text="Home"
                  tooltip="Home">
            <MenuItem text="Music" tooltip="Music">
                <MenuItem navigateurl="Classical.aspx"
                          text="Classical"
                          tooltip="Classical" />
                <MenuItem navigateurl="Rock.aspx"
                          text="Rock"
                          tooltip="Rock" />
                <MenuItem navigateurl="Jazz.aspx"
                          text="Jazz"
                          tooltip="Jazz" />
            </MenuItem>
            <MenuItem navigateurl="Movies.aspx" text="Movies" tooltip="Movies">
                <MenuItem navigateurl="Action.aspx"
                          text="Action"
                          tooltip="Action" />
                <MenuItem navigateurl="Drama.aspx"
                          text="Drama"
                          tooltip="Drama" />
                <MenuItem navigateurl="Musical.aspx"
                          text="Musical"
                          tooltip="Musical" />
            </MenuItem>
        </MenuItem>
    </Items>

</Menu>
```

Examples

Basic Menu with Click Events

<Menu Orientation="Vertical"
      MenuItemClick="HandleMenuClick">
    <Items>
        <MenuItem Text="Home" Value="home" NavigateUrl="/" />
        <MenuItem Text="Products" Value="products">
            <MenuItem Text="Electronics" Value="electronics" NavigateUrl="/electronics" />
            <MenuItem Text="Clothing" Value="clothing" NavigateUrl="/clothing" />
        </MenuItem>
        <MenuItem Text="About" Value="about" NavigateUrl="/about" />
    </Items>
</Menu>

<p>Clicked: @clickedItem</p>

@code {
    private string clickedItem = "";

    private void HandleMenuClick(MenuEventArgs e)
    {
        clickedItem = e.Item.Text;
    }
}

Horizontal Menu

<Menu Orientation="Horizontal"
      SkipLinkText="Skip main navigation"
      Target="_self">
    <Items>
        <MenuItem Text="Home" NavigateUrl="/" />
        <MenuItem Text="Products" NavigateUrl="/products" />
        <MenuItem Text="Services" NavigateUrl="/services" />
        <MenuItem Text="Contact" NavigateUrl="/contact" />
    </Items>
    <StaticMenuItemStyle BackColor="@("SteelBlue")" ForeColor="@("White")" />
    <StaticHoverStyle BackColor="@("LightSteelBlue")" ForeColor="@("Black")" />
</Menu>
<Menu Orientation="Vertical"
      MaximumDynamicDisplayLevels="3"
      StaticDisplayLevels="2">
    <Items>
        <MenuItem Text="File" Value="file">
            <MenuItem Text="New" Value="new" />
            <MenuItem Text="Open" Value="open" />
            <MenuItem Text="Save" Value="save" />
        </MenuItem>
        <MenuItem Text="Edit" Value="edit">
            <MenuItem Text="Cut" Value="cut" />
            <MenuItem Text="Copy" Value="copy" />
            <MenuItem Text="Paste" Value="paste" />
        </MenuItem>
    </Items>
    <StaticMenuItemStyle BackColor="@("LightSteelBlue")" ForeColor="@("Black")" />
    <DynamicMenuItemStyle BackColor="WebColor.Black" ForeColor="WebColor.Silver" />
    <DynamicHoverStyle BackColor="WebColor.LightSkyBlue" ForeColor="WebColor.Black" />
    <DynamicSelectedStyle BackColor="WebColor.PapayaWhip" ForeColor="WebColor.SteelBlue" />
</Menu>

Data Binding with SiteMap

@using System.Xml

<Menu DataSource="@sitemapXml"
      Orientation="Horizontal"
      StaticDisplayLevels="2">
    <DataBindings>
        <MenuItemBinding DataMember="siteMapNode"
                         TextField="title"
                         NavigateUrlField="url" />
    </DataBindings>
</Menu>

@code {
    private XmlDocument sitemapXml;

    protected override void OnInitialized()
    {
        sitemapXml = new XmlDocument();
        sitemapXml.LoadXml(@"
            <siteMap>
                <siteMapNode title='Home' url='/'>
                    <siteMapNode title='Products' url='/products' />
                    <siteMapNode title='About' url='/about' />
                </siteMapNode>
            </siteMap>");
    }
}

Selection and Events Reference

Property/EventTypeDefaultDescription
MenuItemClickEventCallback<MenuEventArgs>Fires when a menu item is clicked.
MenuItemDataBoundEventCallback<MenuEventArgs>Fires when a menu item is data-bound.
SelectedItemMenuItemnullRead-only. The currently selected menu item.
SelectedValuestringnullRead-only. The Value of the selected menu item.
PropertyTypeDefaultDescription
OrientationOrientationVerticalMenu layout direction (Horizontal or Vertical).
TargetstringnullDefault target frame for navigation links.
MaximumDynamicDisplayLevelsint3Max depth of dynamically displayed submenus.
SkipLinkTextstring"Skip Navigation Links"Accessibility skip-link text for screen readers.
StaticDisplayLevelsint1Number of menu levels displayed statically.
PropertyTypeDescription
TextstringDisplay text for the menu item.
ValuestringValue associated with the menu item.
NavigateUrlstringURL to navigate to when clicked.
ToolTipstringTooltip text on hover.
TargetstringTarget frame (falls back to Menu.Target).
ChildContentRenderFragmentNested child MenuItem components.

Style Sub-Components Reference

ComponentApplied To
<StaticMenuItemStyle>Static (always-visible) menu items
<StaticHoverStyle>Static menu items on hover
<DynamicMenuItemStyle>Dynamically displayed submenu items
<DynamicMenuStyle>Dynamic submenu container
<DynamicHoverStyle>Dynamic menu items on hover
<DynamicSelectedStyle>Selected item in dynamic menus

All style components support BackColor, ForeColor, CssClass, BorderColor, BorderStyle, BorderWidth, Font, Height, and Width properties.

See Also