Getting started with Blazor Dropdown Menu component
4 Nov 20255 minutes to read
This guide explains how to integrate the Blazor Dropdown Menu component into a Blazor WebAssembly app using Visual Studio or Visual Studio Code.
Watch the Dropdown Menu getting started video tutorial or explore the GitHub sample project to see the completed application.
Prerequisites
Create a new Blazor app in Visual Studio
Create a Blazor WebAssembly App using Visual Studio via Microsoft templates or the Syncfusion® Blazor Extension.
Install Syncfusion® Blazor SplitButtons and Themes NuGet packages
To add the Blazor Dropdown Menu component, open the NuGet Package Manager in Visual Studio (Tools → NuGet Package Manager → Manage NuGet Packages for Solution), then search for and install Syncfusion.Blazor.SplitButtons and Syncfusion.Blazor.Themes. Alternatively, install them with the Package Manager console:
Install-Package Syncfusion.Blazor.SplitButtons -Version 31.2.12 Install-Package Syncfusion.Blazor.Themes -Version 31.2.12NOTE
Syncfusion® Blazor components are available on NuGet.org. For the list of available packages and component details, see NuGet packages.
Prerequisites
Create a new Blazor app in Visual Studio Code
Create a Blazor WebAssembly App using Visual Studio Code via Microsoft templates or the Syncfusion® Blazor Extension.
Alternatively, create a WebAssembly app from the terminal (Ctrl+`) using the following commands:
dotnet new blazorwasm -o BlazorApp cd BlazorAppInstall Syncfusion® Blazor SplitButtons and Themes NuGet packages
- Press Ctrl+` to open the integrated terminal in Visual Studio Code.
- Ensure in the project root directory that contains the
.csprojfile. - Run the following commands to install the Syncfusion.Blazor.SplitButtons and Syncfusion.Blazor.Themes packages and restore dependencies.
dotnet add package Syncfusion.Blazor.SplitButtons -v 31.2.12 dotnet add package Syncfusion.Blazor.Themes -v 31.2.12 dotnet restoreNOTE
Syncfusion® Blazor components are available on NuGet.org. For the list of available packages and component details, see NuGet packages.
Register Syncfusion® Blazor service
Open ~/_Imports.razor and import the Syncfusion.Blazor and Syncfusion.Blazor.SplitButtons namespaces.
@using Syncfusion.Blazor @using Syncfusion.Blazor.SplitButtonsNext, register the Syncfusion® Blazor service in ~/Program.cs.
using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; using Syncfusion.Blazor; var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add<App>("#app"); builder.RootComponents.Add<HeadOutlet>("head::after"); builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); builder.Services.AddSyncfusionBlazor(); await builder.Build().RunAsync(); ....Add stylesheet and script resources
The theme stylesheet and script are provided via Static Web Assets. Add the references in the <head> section of ~/wwwroot/index.html:
<head> .... <link href="_content/Syncfusion.Blazor.Themes/bootstrap5.css" rel="stylesheet" /> <script src="_content/Syncfusion.Blazor.Core/scripts/syncfusion-blazor.min.js" type="text/javascript"></script> </head>NOTE
Check out the Blazor Themes topic to discover various methods (Static Web Assets, CDN, and CRG) for referencing themes in your Blazor application. Also, check out the Adding Script Reference topic to learn different approaches for adding script references in your Blazor application.
Add Blazor Dropdown Menu component
Add the Syncfusion® Blazor Dropdown Menu component to ~/Pages/Index.razor.
<SfDropDownButton Content="Edit"> <DropDownMenuItems> <DropDownMenuItem Text="Cut"></DropDownMenuItem> <DropDownMenuItem Text="Copy"></DropDownMenuItem> <DropDownMenuItem Text="Paste"></DropDownMenuItem> </DropDownMenuItems> </SfDropDownButton>- Press Ctrl+F5 (Windows) or ⌘+F5 (macOS) to launch the application. The Syncfusion® Blazor Dropdown Menu component renders in the default web browser.
See also
- Getting started with Syncfusion® Blazor for client-side in .NET Core CLI
- Getting started with Syncfusion® Blazor for server-side in Visual Studio
- Getting started with Syncfusion® Blazor for server-side in .NET Core CLI
NOTE
Explore the Blazor Dropdown Menu example to learn how to render and configure the dropdown menu.