A Blazor Viewer application uses the same client-server model as the JS Viewer, so all details on the server-side configurations like Custom Font Resolver or Prevent Cross-Site Scripting Attacks are relevant for a Blazor Viewer as well.
This topic describes how to create a web application that embeds Blazor Viewer.
The following packages are required to be included in the application:
BlazorViewer.razor |
Copy Code
|
---|---|
<div class="main"> <div id="viewerContainer"> <ReportViewer @ref="_viewer" ReportName="@_currentReport" ViewerInitialized="InitializedViewer" DocumentLoaded="@DocumentLoaded"/> </div> </div> |
Let us create a Blazor server application with ActiveReports Blazor Viewer using local report service.
Add a new folder called 'Reports' in application's root and place the report (say, Report.rdlx) you want to display in the viewer, in this folder.
Make sure to set the Build Action property of the report to 'Embedded Resource'.
Add a Razor component to the folder Pages (right-click Pages > Add - Razor component). Set a name for it, for example, BlazorViewer.razor.
BlazorViewer.razor |
Copy Code
|
---|---|
@page "/blazorviewer" <h3>BlazorViewerTest</h3> <div style="width:100%; height: 100vh"> <GrapeCity.ActiveReports.Blazor.Viewer.ReportViewer ReportName="Report.rdlx"></GrapeCity.ActiveReports.Blazor.Viewer.ReportViewer> </div> @code { } |
NavMenu.razor |
Copy Code
|
---|---|
<li class="nav-item px-3"> <NavLink class="nav-link" href="blazorviewer"> <span class="oi oi-list-rich" aria-hidden="true"></span> Blazor Viewer </NavLink> </li> |
ReportService.cs |
Copy Code
|
---|---|
namespace BlazorApp1.Data { public class ReportsService { public static string EmbeddedReportsPrefix = "BlazorApp1.Reports"; public IEnumerable<string> GetReports() { string[] validExtensions = { ".rdl", ".rdlx", ".rdlx-master", ".rpx" }; return GetEmbeddedReports(validExtensions); } private static string[] GetEmbeddedReports(string[] validExtensions) => typeof(ReportsService).Assembly.GetManifestResourceNames() .Where(x => x.StartsWith(EmbeddedReportsPrefix)) .Where(x => validExtensions.Any(x.EndsWith)) .Select(x => x.Substring(EmbeddedReportsPrefix.Length + 1)) .ToArray(); } } |
Program.cs |
Copy Code
|
---|---|
builder.Services.AddSingleton<ReportsService>();
app.UseReportViewer(settings =>
{
settings.UseEmbeddedTemplates(ReportsService.EmbeddedReportsPrefix, Assembly.GetAssembly(typeof(ReportsService)));
});
|
Here we describe creating the application using built-in ActiveReports application template. This application uses remote report service.
The following required packages are automatically added to the project:
Open the report from the 'Reports' folder and design.
Make sure to set multiple startup projects:
Add a new folder called 'Reports' in application's root and place the report (say, Report.rdlx) you want to display in the viewer, in this folder.
Make sure to set the Build Action property of the report to 'Embedded Resource'.
Update the existing Index.razor page as follows:
BlazorViewer.razor |
Copy Code
|
---|---|
@page "/" @using MESCIUS.ActiveReports.Blazor.Viewer <PageTitle>Index</PageTitle><div style="width:100%; height: 100vh"> <ReportViewer ReportName="Report.rdlx" ReportService="@_reportService"></ReportViewer></div> @code{ private ReportServiceSettings _reportService = new ReportServiceSettings() { Url = "http://localhost:58865/", }; } |