Skip to main content
All docs

Open a Report in ASP.NET Core Application

  • 4 minutes to read

This topic describes several ways to display a report in a Document Viewer Control. It also addresses common issues that may occur when the DevExpress Document Viewer opens a report.

Specify a Report

Once incorporated into a web page, the DevExpress Document Viewer control can automatically load a report at “startup.” The Bind method allows you to bind the Document Viewer to a View Model or report. You can create a new report instance and pass it as the parameter or specify a report by name.

@model DevExpress.XtraReports.Web.WebDocumentViewer.WebDocumentViewerModel;
    var viewerRender = Html.DevExpress().WebDocumentViewer("DocumentViewer")

Bind to a View Model

Your controller must use the WebDocumentViewerClientSideModelGenerator object to create a View Model. You can call the GetModel method overload to create a report model and pass it to the view.

This strategy allows you to generate reports asynchronously. You can call the UseAsyncEngine method (at app startup) to activate asynchronous mode, and use the GetModelAsync method to proceed:

using DevExpress.AspNetCore.Reporting.WebDocumentViewer;
using DevExpress.XtraReports.Web.WebDocumentViewer;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
// ...
    public class HomeController : Controller {        
        public async Task<IActionResult> Index([FromQuery] string reportName = "MainReport") {
            var modelGenerator = new WebDocumentViewerClientSideModelGenerator(HttpContext.RequestServices);
            var model = await modelGenerator.GetModelAsync(reportName, WebDocumentViewerController.DefaultUri);
            return View(model);

Pass a Report Instance

You can instantiate a report and pass it to the Bind method as necessary. This approach consumes more memory because a new report instance is generated when the page reloads.

You can pass the CachedReportSourceWeb instance to the Bind method to optimize memory usage. As its name implies, our CachedReportSourceWeb object caches a document once generated.

Specify a Report Name

If you specify a report name as the Bind method parameter, the Document Viewer uses report name resolution services (described below) to obtain the report by name.

You can also use client-side APIs and call the OpenReport method of the client Document Viewer object, or handle the Document Viewer client-side event and call the OpenReport method of the event sender object. These methods accept report name as a parameter and use report name resolution services.

Use Report Name Resolution Services

If you pass report name to a method that opens a report, you must implement and register one of the following services (to resolve report names).

A 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.
This 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.

The following services have a higher priority than the previously mentioned services, although the scope of their use is limited.


Allows you to parse a report name, create a report instance, and return it to the calling method. If you have a parameterized report, you can specify parameters in the report name passed to the service and use parameters within the report’s constructor.

The IWebDocumentViewerReportResolver service is Intended for use only with the Web Document Viewer, and enables you to implement name resolution differently in the Report Designer and Document Viewer. The XRSubreport control does not use this service.

The IWebDocumentViewerReportResolver service does not support asynchronous mode.

Open Subreports

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 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 Document Viewer passes the XRSubreport.ReportSourceUrl property value to available report name resolution services. You can use the IReportProvider service IReportProvider to resolve report names for both the main report and subreports.

When both IWebDocumentViewerReportResolver and IReportProvider services are available, the IWebDocumentViewerReportResolver service resolves the main report name while the IReportProvider service is called to resolve the subreport name.