Search results

Getting Started

This section briefly explains about how to include Blazor Menu in your Blazor client-side application. You can refer Getting Started with Syncfusion Blazor for Client-side in Visual Studio 2019 Preview page for introduction and configure the common specifications.

Importing Syncfusion Blazor component in the application

  1. Install Syncfusion.EJ2.Blazor NuGet package to the application by using the NuGet Package Manager. Please ensure to check the Include prerelease option.
  2. You can add the client-side resources through CDN or local npm package in the <head> element of the ~/wwwroot/index.html page.
<head>
    <environment include="Development">
        <link href="https://cdn.syncfusion.com/ej2/17.3.29/material.css" rel="stylesheet" />
        <script src="https://cdn.syncfusion.com/ej2/17.3.29/dist/ej2.min.js"></script>
     </environment>
</head>

Adding component package to the application

Open /_Imports.razor file and import the Syncfusion.EJ2.Blazor.Navigations packages otherwise import these packages in the individual razor pages.

@using Syncfusion.EJ2.Blazor
@using Syncfusion.EJ2.Blazor.Navigations

Adding Menu component to the application

Now, add the Blazor Menu component in razor page in the Pages folder. For example, the Menu component is added in the ~/Pages/Index.razor page.

@using Syncfusion.EJ2.Blazor.Navigations

<EjsMenu Items="@MenuItems"></EjsMenu>

@code {
    public List<MenuItem> MenuItems = new List<MenuItem>{
        new MenuItem{ Text = "File", Items = new List<MenuItem>{
            new MenuItem{ Text= "Open" },
            new MenuItem{ Text= "Save" },
            new MenuItem{ Text= "Exit" }}
    },
        new MenuItem{ Text = "Edit", Items = new List<MenuItem>{
            new MenuItem{ Text= "Cut" },
            new MenuItem{ Text= "Copy" },
            new MenuItem{ Text= "Paste" }}
    },
        new MenuItem{ Text = "View", Items = new List<MenuItem>{
            new MenuItem{ Text = "Toolbars" },
            new MenuItem{ Text = "Zoom" },
            new MenuItem{ Text = "Full Screen" }}
    },
        new MenuItem{ Text = "Tools", Items = new List<MenuItem>{
            new MenuItem{ Text= "Spelling & Grammar" },
            new MenuItem{ Text= "Customize" },
            new MenuItem{ Text= "Options" }}
    },
        new MenuItem{ Text = "Go" },
        new MenuItem{ Text = "Help" }
    };
}

Run the application

After successful compilation of your application, simply press F5 to run the application. The Blazor Menu component will render in the web browser as shown below

Menu Sample

See Also