Getting Started with ASP.NET Core Toolbar Control

23 Jul 20265 minutes to read

This section briefly explains how to include the ASP.NET Core Toolbar control in your ASP.NET Core Web App using Visual Studio.

Create ASP.NET Core Web App with Razor Pages

Create an ASP.NET Core Web App using Visual Studio via Microsoft Templates or the ASP.NET Core Extension.

Install the required ASP.NET Core packages

To add ASP.NET Core Toolbar control in the app, open the NuGet package manager in Visual Studio (Tools → NuGet Package Manager → Manage NuGet Packages for Solution), then search and install Syncfusion.AspNetCore.Navigations and Syncfusion.AspNetCore.Themes. All Syncfusion ASP.NET Core packages are available in nuget.org. See the NuGet packages topic for more details.

Alternatively, you can install the same packages using the Package Manager Console with the following commands.

Install-Package Syncfusion.AspNetCore.Navigations -Version 34.1.29
Install-Package Syncfusion.AspNetCore.Themes -Version 34.1.29

Add ASP.NET Core tag helpers

After the packages are installed, open the ~/Pages/_ViewImports.cshtml file and import the Syncfusion.AspNetCore.Navigations and Syncfusion.AspNetCore.Base tag helpers.

@addTagHelper *, Syncfusion.AspNetCore.Navigations
@addTagHelper *, Syncfusion.AspNetCore.Base

Add stylesheet and script resources

The theme stylesheet and script can be referenced from NuGet through Static Web Assets. Include the stylesheet and script references inside the <head> of ~/Pages/Shared/_Layout.cshtml file.

<head>
    ...
    ...
    <link rel="stylesheet" href="_content/Syncfusion.AspNetCore.Themes/styles/fluent2.css" />
    <script src="_content/Syncfusion.AspNetCore.Navigations/scripts/sf-toolbar.min.js"></script>
</head>

Register the script manager

Open the ~/Pages/Shared/_Layout.cshtml file and register the script manager (<ejs-scripts>) at the end of the <body> element as shown below.

<body>
    ...
    <!-- Syncfusion ASP.NET Core Script Manager -->
    <ejs-scripts></ejs-scripts>
</body>

Add the ASP.NET Core Toolbar control

Add the ASP.NET Core Toolbar control in the ~/Pages/Index.cshtml file.

<ejs-toolbar id="defaultToolbar" width="600px">
    <e-toolbar-items>
        <e-toolbar-item text="Cut" prefixIcon="e-cut-icon tb-icons" tooltipText="Cut"></e-toolbar-item>
        <e-toolbar-item text="Copy" prefixIcon="e-copy-icon tb-icons" tooltipText="Copy"></e-toolbar-item>
        <e-toolbar-item text="Paste" prefixIcon="e-paste-icon tb-icons" tooltipText="Paste"></e-toolbar-item>
        <e-toolbar-item type="Separator"></e-toolbar-item>
        <e-toolbar-item text="Bold" prefixIcon="e-bold-icon tb-icons" tooltipText="Bold"></e-toolbar-item>
        <e-toolbar-item text="Underline" prefixIcon="e-underline-icon tb-icons" tooltipText="Underline"></e-toolbar-item>
        <e-toolbar-item text="Italic" prefixIcon="e-italic-icon tb-icons" tooltipText="Italic"></e-toolbar-item>
        <e-toolbar-item text="Color Picker" prefixIcon="e-color-icon tb-icons" tooltipText="Color-Picker"></e-toolbar-item>
    </e-toolbar-items>
</ejs-toolbar>

Press Ctrl+F5 (Windows) or +F5 (macOS) to launch the application. The ASP.NET Core Toolbar control will render in your default web browser.

ASP.NET Core Toolbar Control

Render the Toolbar items using content template

You can customize Toolbar items by rendering HTML elements or Syncfusion components through the content template. This allows you to place interactive controls directly within the Toolbar.

In the following example, Button, MaskedTextBox, RadioButton, DropDownList controls are added to the Toolbar using the content template. Define these controls within the content template property to render them as Toolbar items, as shown in the code below.

@{
    .....
    var data = new string[] { "Badminton", "Basketball", "Cricket", "Football", "Golf", "Gymnastics", "Hockey", "Tennis" };
}

<ejs-toolbar id="default">
    <e-toolbar-items>
        <e-content-template>
            <div>
                <div> <ejs-button id="btn" content="Click" isPrimary="true"></ejs-button></div>
                <div class='e-separator'> </div>
                <div> <ejs-maskedtextbox id="mask1" mask="345-678-4673"></ejs-maskedtextbox> </div>
                <div class='e-separator'> </div>
                <div>  <ejs-radiobutton id="radio1" label="Credit/Debit Card" name="payment" value="credit/debit"></ejs-radiobutton> </div>
                <div class='e-separator'> </div>
                <div>
                    <ejs-dropdownlist id="games" dataSource="@data" placeholder="Select a game" index="2" popupHeight="220px" />
                </div>
            </div>
        </e-content-template>
    </e-toolbar-items>
</ejs-toolbar>
<style>
    .separator {
        width: 10px;
    }
</style>
public ActionResult Index()
{
    ViewBag.data = new string[] { "Badminton", "Basketball", "Cricket", "Football", "Golf", "Gymnastics", "Hockey", "Tennis" };
    return View();
}

content template

NOTE

View Sample in GitHub.

See also

  1. Getting Started with ASP.NET Core in Visual Studio Mac
  2. Getting Started with ASP.NET Core MVC using Tag Helper