Skip to main content
A newer version of this page is available. .
All docs
V21.1

Add a Web Dashboard to a Blazor Server Application

  • 2 minutes to read

This topic describes how to add the DxDashboard component to a Blazor Server application. The Dashboard component wraps the JavaScript DashboardControl and uses an ASP.NET Core backend with the Dashboard Controller to handle client data requests.

You can also download the example:

View Example: Get Started - Dashboard Component in Blazor Server Application

Prerequisites

To use the Dashboard component for Blazor, make sure that the following requirements are met:

Install the NuGet Packages

Install the following NuGet packages in your project:

  • DevExpress.AspNetCore.Dashboard
  • DevExpress.Blazor.Dashboard

Configure Backend

In the Startup.cs file, modify the ConfigureServices method:

  • Add services for DevExpress Controls.
  • Set up dashboard storage.
  • Set up data source storage.
using DevExpress.AspNetCore;
using DevExpress.DashboardAspNetCore;
using DevExpress.DashboardCommon;
using DevExpress.DashboardWeb;
using Microsoft.Extensions.FileProviders;
using System;
// ...
public Startup(IConfiguration configuration) {
    Configuration = configuration;
}

public IConfiguration Configuration { get; }

public void ConfigureServices(IServiceCollection services) {
    // ...
    services.AddDevExpressControls();
    services.AddMvc()
            .AddDefaultDashboardController(configurator => {                
                configurator.SetDashboardStorage(new DashboardInMemoryStorage());
                configurator.SetDataSourceStorage(new DataSourceInMemoryStorage());
                // ...
            });
    // ...
}

Note

You can also create a folder to store dashboards in a file system: Prepare Dashboard Storage

In the same file, add the app.UseDevExpressControls() and EndpointRouteBuilderExtension.MapDashboardRoute() method calls to the Configure method in the following order:

// ...
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
    // ...
    app.UseStaticFiles();
    app.UseDevExpressControls();
    app.UseRouting();

    app.UseEndpoints(endpoints => {
        EndpointRouteBuilderExtension.MapDashboardRoute(endpoints, "api/dashboard");
        // ...
    });
}

Add Stylesheets

In the Pages folder, open the _Host.cshtml file and reference the following stylesheets:

<head>
    ...
    <link href="_content/DevExpress.Blazor.Dashboard/dx.light.css" rel="stylesheet" />
    <link href="_content/DevExpress.Blazor.Dashboard/dx-analytics.common.css" rel="stylesheet" />
    <link href="_content/DevExpress.Blazor.Dashboard/dx-analytics.light.css" rel="stylesheet" />
    <link href="_content/DevExpress.Blazor.Dashboard/dx-querybuilder.css" rel="stylesheet" />
    <link href="_content/DevExpress.Blazor.Dashboard/dx-dashboard.light.min.css" rel="stylesheet" />
</head>

Add References

Reference the DevExpress.DashboardBlazor and DevExpress.DashboardWeb namespaces. For example, you can do this in the _Imports.razor file alongside with the existing references:

...
@using DevExpress.DashboardBlazor
@using DevExpress.DashboardWeb

Add the Dashboard Component

Add the code below to a Razor page to render the Web Dashboard. Specify the same endpoint as in the EndpointRouteBuilderExtension.MapDashboardRoute method call:

<DxDashboard Endpoint="api/dashboard" style="width: 100%; height: 800px;">
</DxDashboard>

See the following topic for information on how to configure the Dashboard component: Property Binding in Blazor.

Next Steps

You can do the following to prepare the control for first use: