How to: Access the Report Preview Control (Blazor)
This example demonstrates how to access the adapter of the DxDocumentViewer component that ASP.NET Core Blazor XAF applications use to display reports.
When a user previews a report, an ASP.NET Core Blazor application opens a Detail View that contains ReportViewerViewItem. Follow the steps below to access this View Item and its component:
- Add the DevExpress.ExpressApp.ReportsV2.Blazor NuGet package to the ASP.NET Core Blazor module project (MySolution.Module.Blazor). If your solution does not contain this project, add this package to the application project (MySolution.Blazor.Server).
- Create a View Controller. Set its View property to DetailView and TargetViewId to the View’s identifier. The ReportsBlazorModuleV2.ReportViewerDetailViewName constant stores this identifier.
- In the overridden OnActivated method, call the CustomizeViewItemControl<T>(DetailView, Controller, Action<T>) method.
- Use the ViewItem.Control property to access the Report Viewer’s control.
File:
MySolution.Blazor.Server\Controllers\AccessReportViewerController.cs in solutions without the ASP.NET Core Blazor-specific module project.
MySolution.Module.Blazor\Controllers\AccessReportViewerController.cs in solutions with the ASP.NET Core Blazor-specific module project.
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.ReportsV2.Blazor;
// ...
public class AccessReportViewerController : ViewController<DetailView> {
public AccessReportViewerController() {
TargetViewId = ReportsBlazorModuleV2.ReportViewerDetailViewName;
}
protected override void OnActivated() {
base.OnActivated();
View.CustomizeViewItemControl<ReportViewerViewItem>(this, CustomizeReportViewerViewItem);
}
private void CustomizeReportViewerViewItem(ReportViewerViewItem reportViewerViewItem) {
string reportName = ((ReportViewerViewItem.DxDocumentViewerAdapter)reportViewerViewItem.Control).ComponentModel.ReportName;
// ...
}
}