New to Telerik Reporting? Download free 30-day trial

How to Use Blazor Report Viewer

The following article guides you how to use Blazor Report Viewer in a Blazor web application.

Prerequisites

  • Visual Studio 2019, version 16.4 or later

  • Existing ASP.NET Core 3.1 and higher Blazor Server App or ASP.NET Core 3.1 and higher hosted Blazor WebAssembly App

  • The report viewer consumes reports generated and served from a running Reports Web Service. Such can be referenced from another application or Telerik Report Server instance, or it can be hosted locally in a Blazor Server application.

  • Blazor WebAssembly applications are executed directly on the browser UI thread. In other words, Blazor WebAssembly are stictly client-side applications and the Reports Web Service cannot be hosted in the same project. When using Blazor WebAssembly, the Reports Web Service has to be hosted in a separate project or Telerik Report Server may be used. For more information, see Blazor WebAssembly vs. Server. To host the Reporting Service locally, please follow the approach from either the How to Host Reports Service in ASP.NET Core 3.1 or the How to Host Reports Service in ASP.NET Core in.NET 5 articles.

Adding the HTML5 Report Viewer component

  1. Add NuGet package reference to the Telerik.ReportViewer.Blazor (or Telerik.ReportViewer.Blazor.Trial) package hosted on the Progress Telerik proprietary NuGet feed. Make sure you have the needed NuGet feed added to VS setting using the article How to add the Telerik private NuGet feed to Visual Studio.

  2. Make sure app configuration inside the Configure method of the Startup.cs can serve static files:

    app.UseStaticFiles();
    
  3. Add JavaScript dependencies to the head element of the Pages/_Host.cshtml (Blazor Server) or wwwroot/index.html (Blazor WebAssembly):

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js" /script>
    @* For Reports service hosted in the same project: *@
    <script src="/api/reports/resources/js/telerikReportViewer" /script>
    @* For Reports service hosted in another application / Report Server use absolute URI: *@
    @*<script src="https://demos.telerik.com/report-server/api/reports/resources/js/telerikReportViewer" /script>*@
    
  4. Add Telerik Kendo UI Sass-Based Themes to the head element of the Pages/_Host.cshtml (Blazor Server) or wwwroot/index.html (Blazor WebAssembly). The Razor syntax for a server application differs and you need to escape the @ symbol as @@ :

    <link rel="stylesheet" href="https://unpkg.com/@progress/kendo-theme-default@latest/dist/all.css" />
    

    Alternatively you can use the Kendo UI Less-Based Themes (Kendo UI Less-Based Themes are not compatible with Telerik UI for Blazor and should not be used together):

    <link href="https://kendo.cdn.telerik.com/2022.1.301/styles/kendo.common.min.css" rel="stylesheet" />
    <link href="https://kendo.cdn.telerik.com/2022.1.301/styles/kendo.blueopal.min.css" rel="stylesheet" />
    
  5. Add the dedicated interop.js dependency at the end of the body element of the Pages/_Host.cshtml (Blazor Server) or wwwroot/index.html (Blazor WebAssembly):

    <script src="_content/Telerik.ReportViewer.Blazor/interop.js" defer /script>
    @* Or this one if using the Telerik.ReportViewer.Blazor.Trial package *@
    @*<script src="_content/Telerik.ReportViewer.Blazor.Trial/interop.js" defer /script>*@
    
  6. If using Reports web service (either locally hosted or in another application) use the following snippet to place the viewer component in a razor page like Pages/Index.razor. Note that when referencing the Reports service from another application the ServiceUrl setting should be the absolute URI to the service. Remember to set the actual ReportSource along with eventual parameters:

    @page "/"
    @using Telerik.ReportViewer.Blazor
    <style>
        #rv1 {
            position: relative;
            width: 1200px;
            height: 600px;
        }
    </style>
    <ReportViewer ViewerId="rv1"
                  ServiceUrl="/api/reports"
                  ReportSource="@(new ReportSourceOptions()
                                  {
                                        Report = "YOUR_REPORT_HERE.trdp"
                                  })"
                  Parameters="@(new ParametersOptions { Editors = new EditorsOptions { MultiSelect = EditorType.ComboBox, SingleSelect = EditorType.ComboBox } })"
                  ScaleMode="@(ScaleMode.Specific)"
                  Scale="1.0" />
    
  7. If displaying reports from a Report Server instance use the following snippet to place the viewer component in a razor page like Pages/Index.razor. Remember to set the actual ReportServer and ReportSource settings:

    @page "/"
    @using Telerik.ReportViewer.Blazor
    <style>
        #rv1 {
            position: relative;
            width: 1200px;
            height: 600px;
        }
    </style>
    <ReportViewer ViewerId="rv1"
                  ReportServer="@(new ReportServerOptions {  Url = "https://demos.telerik.com/report-server/", Username = "demouser", Password = "demopass" })"
                  ReportSource="@(new ReportSourceOptions()
                                  {
                                        Report = "Published/Dashboard"
                                  })"
                  ScaleMode="@(ScaleMode.Specific)"
                  Scale="1.0" />
    
  8. Use the rest of the parameters exposed on the Blazor viewer component to setup its appearance and behavior as desired.

  9. Finally, run the project to see the rendered report.

Learn more about Blazor Reporting in Integration with Telerik Reporting documentation article.

In this article