Skip to main content
All docs
V25.2
  • Add a Report Viewer to a Project (Blazor Web App Created with a Visual Studio Template)

    • 4 minutes to read

    Prerequisites

    1. .NET 8.0 or later SDK.
    2. Visual Studio 2022 with the ASP.NET and web development workload.

    Create a New Project

    This section describes how to create a new Blazor project. If you want to start this tutorial using an existing application, go to Step 2.

    1. Click Create a new project on Visual Studio’s start page and select the Blazor Web App template. Select Server from the Interactive Render Mode drop-down list.

      Blazor Web App Template — Additional Settings

      Click Next.

    2. Specify the project name and location, and click Next.

    3. Specify additional options and click Create.

    For additional information on available Blazor templates, refer to the following topic: Tooling for ASP.NET Core Blazor.

    Install NuGet Packages

    Install a NuGet package for the Blazor Report Viewer:

    1. Select ToolsNuGet Package ManagerManage NuGet Packages for Solution.

    2. Once the dialog appears, open the Browse tab, select the DevExpress 25.2 Local package source, and install the following NuGet package:

      • DevExpress.Blazor.Reporting.Viewer

      The DevExpress 25.2 Local package is automatically added as a package source to your NuGet configuration files if you used the DevExpress .NET Product Installer.

      Getting Started - Install Package

    3. Build the project.

    Refer to the following help topic for more information: Install NuGet Packages in Visual Studio, VS Code, and Rider.

    Register DevExpress Resources

    1. In the _Imports.razor file, register the DevExpress.Blazor namespace:

      @using DevExpress.Blazor
      
    2. Register scripts required by DevExpress components: open the App.razor file and call the DxResourceManager.RegisterScripts method.

      <head>
          @*...*@
          @DxResourceManager.RegisterScripts()
          @*...*@
      </head>
      
    3. Register the services required for Blazor Reporting, and specify endpoint routing. For this, call the AddDevExpressServerSideBlazorReportViewer method in the Program.cs file:

      using Microsoft.AspNetCore.Components;
      using Microsoft.AspNetCore.Components.Web;
      // ...
      
      var builder = WebApplication.CreateBuilder(args);
      
      // ...
      builder.Services.AddDevExpressServerSideBlazorReportViewer();
      
      builder.WebHost.UseWebRoot("wwwroot");
      builder.WebHost.UseStaticWebAssets();
      
      var app = builder.Build();
      
      // ...
      
      app.Run();
      
    4. Apply a theme in the Components/App.razor project file.

      • Classis Blazing Berry Theme

        <head>
            @*...*@
            @DxResourceManager.RegisterTheme(Themes.BlazingBerry)
            <link rel="stylesheet" href="_content/DevExpress.Blazor.Reporting.Viewer/css/dx-blazor-reporting-components.bs5.css">
        </head>
        
      • Fluent Light Blue Theme

        <head>
            @*...*@
            @DxResourceManager.RegisterTheme(Themes.Fluent)
            <link rel="stylesheet" href="_content/DevExpress.Blazor.Reporting.Viewer/css/dx-blazor-reporting-components.fluent.css">
        </head>
        

      For additional information on themes, refer to the following help topic: Themes in Blazor Report Viewer.

    Add a Report Viewer to the Page

    1. Create a new file (ReportViewer.razor) in the Pages folder.

      Enable interactivity for DevExpress components:

      • Make sure the required interactive services are registered in the Program.cs file.
      • Add the corresponding render mode attribute to a component’s page.

      Use the following code to generate a page with a Report Viewer component:

      @page "/Viewer"
      @rendermode InteractiveServer
      
      @using DevExpress.Blazor.Reporting
      
      <h3>Report Viewer</h3>
      
      <DxReportViewer @ref="reportViewer">
      </DxReportViewer>
      
      @code {
          DxReportViewer? reportViewer;
      }
      
    2. Add a navigation link to the NavMenu.razor page:

      <div class="nav-item px-3">
          <NavLink class="nav-link" href="viewer">
              <span class="oi oi-list-rich" aria-hidden="true"></span> Report Viewer
          </NavLink>
      </div>
      

    Run the Project

    Run the project. When the browser opens the application, navigate to the Viewer page:

    Empty DevExpress Report Viewer

    Load a Report

    Create a report class and pass an instance of this class to the viewer.

    Create a New Report

    To perform this step, you should install DevExpress Reporting v25.2 on your machine. Refer to the following topic for more information: Run the Installation Wizard - DevExpress Unified Component Installer.

    1. Select Project -> Add New Item… to invoke the Add New Item dialog. Navigate to the Reporting node and select the DevExpress v.25.2 Report item template.

      Add a New Report

      Name the report TestReport.cs and click Add.

    2. Select Blank in the invoked Report Wizard page and click Finish.

      Report Wizard New Blank Report

    3. Modify the newly created report in the Visual Studio Report Designer. Add a label and type Hello, World!:

      Edit a Report in the VS Designer

    4. Click the report’s smart tag and select Save…:

      Save New Report

      In the invoked Save As dialog, specify the Reports project folder, Report XML Files (.repx) file type, and the TestReport.repx file name.

    Pass the Report to the Viewer

    1. Specify the report that the Report Viewer displays in the ReportViewer.razor page:

      @page "/viewer"    
      @rendermode InteractiveServer
      
      @using DevExpress.Blazor.Reporting
      @using DevExpress.XtraReports.UI;
      
      <h3>Viewer</h3>
      
      <link href="_content/DevExpress.Blazor.Themes/blazing-berry.bs5.min.css" rel="stylesheet" />
      <link rel="stylesheet" href="_content/DevExpress.Blazor.Reporting.Viewer/css/dx-blazor-reporting-components.bs5.css">
      
      <DxReportViewer @ref="reportViewer" Report="@Report">
      </DxReportViewer>
      
      @code {
          DxReportViewer reportViewer { get; set; }
          TestReport Report = new TestReport();
      }
      
    2. Run the project and see the result.

    Next Steps

    Load a Report
    Topic describes how to load predefined reports and load reports from REPX files.
    Restore Data Connections
    Topic describes how to implement a service that resolves a SQL/JSON connection name to a valid connection.
    Specify Report Parameters
    Topic describes how to specify report parameters using the built-in Parameters Panel or create custom UI elements and use them to submit parameter values to the report.
    Customize the Report Viewer

    Review the following topics for information on how to customize the UI:

    Troubleshooting
    Topic lists common issues that can occur in a Web Reporting application and describes solutions. For information on how to identify the cause of an issue, refer to the following topic: Reporting Application Diagnostics.