Back to Devexpress

Add a JavaScript-Based Document Viewer to a Blazor Web App (Interactive WebAssembly) with an ASP.NET Core Backend

xtrareports-404096-web-reporting-blazor-reporting-web-document-viewer-get-started-get-started-blazor-wasm-hosted.md

latest8.5 KB
Original Source

Add a JavaScript-Based Document Viewer to a Blazor Web App (Interactive WebAssembly) with an ASP.NET Core Backend

  • Feb 16, 2026
  • 6 minutes to read

This tutorial adds a Document Viewer (DxWasmDocumentViewer) to an application created with the Blazor Web App (Interactive WebAssembly) template.

Create a New Project from a Template

This section describes how to create a new Blazor project. If you wish 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 WebAssembly from the Interactive Render Mode drop-down list.

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

  3. Specify additional options and click Create.

You can use this tutorial to integrate the Standalone Report Parameters Panel into a Blazor WebAssembly Hosted (available in ASP.NET Core 7.0 or earlier) template.

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

Install NuGet Packages

  1. Install the following NuGet packages to the projects:

  2. Build the project.

Register DevExpress Resources

  1. In the main project’s Program.cs file, add the following code:

  2. In the Client project’s _Imports.razor file, register the DevExpress.Blazor.Reporting namespace:

  3. In the App.razor file, call the RegisterScripts(Action<ResourcesConfigurator>) method to register DevExpress client resources:

Implement a Document Viewer Controller

  1. Create a Controllers folder.
  2. In the created folder, add a new ReportingControllers.cs class file with the following content:

Create a Sample Report

Note

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

  1. Switch to the BlazorWasmReportingApp project. 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.

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

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

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

Implement a Report Name Resolution Service

The Document Viewer control loads a report specified by name and needs a service to resolve a report name to a report instance. To create such a service, you must implement and register one of the following services (to resolve report names):

IReportProviderA recommended service for the Document Viewer and Report Designer. The primary advantage of IReportProvider service is that it can be attached to reports created at runtime. IReportProviderAsync uses asynchronous operations.ReportStorageWebExtensionThis service is called when no other report name resolution services are available. It is designed to obtain reports (stored in our REPX format) from external storage (a file or a database). Note that the GetData method returns a serialized report. If you use the GetData method to specify the default parameter value for a loaded report, set the Value property to the parameter value.

In this example, we implement the IReportProvider service. The IReportProvider interface has the GetReport method that gets a report name and returns a report instance. In this tutorial, the GetReport method calls the static ReportFactory class. The ReportFactory class contains the dictionary of report names and report instances.

  1. Add the ReportFactory.cs class file to the server project with the following code:

  2. Add the ReportProvider.cs class file to the server project with the following code:

  3. In the Program.cs file, register the ReportProvider service:

Create a Page with the Document Viewer

Create a new Razor page (DocumentViewer.razor) in the Client/Pages folder. Use the code below to generate a page with a Document Viewer component.

Enable interactivity for DevExpress components:

razor
@page "/viewer"

<DxWasmDocumentViewer ReportName="TestReport" Height="700px" Width="100%">
    <DxDocumentViewerExportSettings UseSameTab=false>
    </DxDocumentViewerExportSettings>
    <DxWasmDocumentViewerRequestOptions InvokeAction="DXXRDV">
    </DxWasmDocumentViewerRequestOptions>
</DxWasmDocumentViewer>

The DxWasmDocumentViewer component invokes the default WebDocumentViewerController that processes requests from the Document Viewer and loads the TestReport report.

Modify the NavMenu.razor file to include links to the newly created pages.

razor
<div class="nav-item px-3">
    <NavLink class="nav-link" href="documentviewer">
        <span class="oi oi-plus" aria-hidden="true"></span> Document Viewer
    </NavLink>
</div>

Run the Project

Run the project. The Document Viewer loads the TestReport report:

Next Steps

Restore Data ConnectionsLearn how to implement a service that restores data connections for data-aware reports loaded in the Document Viewer.Specify Report Parameters Learn 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.Handle Client-Side EventsLearn how to handle client-side events raised by the JavaScript-based Document Viewer.Customize Parameter EditorsLearn how to customize built-in parameter editors in the JavaScript-based Document Viewer.Customize the Tab PanelLearn how to customize the Document Viewer Tab Panel.Customize the ToolbarLearn how to customize the Document Viewer Toolbar.TroubleshootingThis 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 help topic: Reporting Application Diagnostics.