xtrareports-403611-web-reporting-blazor-reporting-native-report-viewer-load-a-report.md
This document describes how to open a report in the Blazor Report Viewer.
You can instantiate a report (an XtraReport or CachedReportSource instance) and use one of the following options to load the report to the Report Viewer:
The DxReportViewer.Report property
Assign an XtraReport instance (or CachedReportSource instance for large documents) to the Report property to open a report:
@page "/reportviewer/"
@using DevExpress.Blazor.Reporting
@using DevExpress.XtraReports.UI
@using DXApplication.PredefinedReports
<DxReportViewer @ref="reportViewer" Report="Report"/>
@code {
DxReportViewer reportViewer;
XtraReport Report = new TestReport();
}
The DxReportViewer.OpenReportAsync(IReport) method
Allows you to load a report asynchronously. Pass an XtraReport instance (or CachedReportSource instance for large documents):
@page "/reportviewer/"
@using DevExpress.Blazor.Reporting
@using DevExpress.XtraReports.UI
@using DXApplication.PredefinedReports
<DxReportViewer @ref="reportViewer"/>
@code {
DxReportViewer reportViewer;
XtraReport Report = new TestReport();
protected override void OnAfterRender(bool firstRender) {
if (firstRender) {
reportViewer.OpenReportAsync(Report);
}
}
}
If you pass a report name to the Report property or the OpenReportAsync method, you need to implement IReportProvider / IReportProviderAsync and register it at application startup. This service resolves a report name to a report instance.
Implement the IReportProvider interface. The following code snippet creates a service that translates the report name to the report instance:
Register the service at application startup:
Pass the report name to the DxReportViewer.Report property or DxReportViewer.OpenReportAsync(IReport) method.
The XRSubreport control defines additional reports (subreports) included in the host report. The control’s ReportSource property specifies the report instance used as a subreport, and the ReportSourceUrl property specifies the report name. The ReportSourceUrl property has priority over the ReportSource property.
A subreport is opened automatically alongside the main report. To open a subreport, the Report Viewer passes the XRSubreport.ReportSourceUrl property value to available report name resolution services. Use the IReportProviderAsync service to resolve report names for both the main report and subreports.