All docs
V20.2
20.2
20.1
The page you are viewing does not exist in version 20.1. This link will take you to the root page.
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

Open a Report in ASP.NET Core Application

  • 4 minutes to read

This topic describes common scenarios for how to open reports. It also addresses issues that may occur when the Document Viewer opens a report.

Specify a Report

When you add the Document Viewer control to the page, you can specify the report that the Document Viewer loads on 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 the report by its name.

@model DevExpress.XtraReports.Web.WebDocumentViewer.WebDocumentViewerModel;
//...
@{
    var viewerRender = Html.DevExpress().WebDocumentViewer("DocumentViewer")
        .Height("1000px")
        .Bind(Model);
    @viewerRender.RenderHtml()
}

Bind to the View Model

Your controller should 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.

The advantage of this technique is that it allows you to use an asynchronous task for report creation. You can call the UseAsyncEngine method at application startup to enable asynchronous mode, and use the GetModelAsync method:

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. This technique consumes more memory because a new report instance is created when the page reloads.

You can pass the CachedReportSourceWeb instance to the Bind method to optimize memory usage. The CachedReportSourceWeb object caches document pages when they are 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 a report by name.

You can also use the client-side API 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 a report name as the parameter and use report name resolution services.

Use Report Name Resolution Services

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

  • The IWebDocumentViewerReportResolver service allows you to parse a report name, create a report instance and return it to the calling method. When you have a parameterized report, you can specify parameters in the report name that is passed to the service, and use parameters in the report's constructor.

  • The ICachedReportSourceWebResolver service returns the CachedReportSourceWeb instance. It has an asynchronous counterpart - the ICachedReportSourceWebResolverAsync service that allows you to build a document asynchronously.

  • The IReportProvider service has lower priority than the previously mentioned services. However, it is not intended for exclusive use by the Document Viewer. The main advantage of IReportProvider service is that it can be attached to reports created at runtime. The IReportProviderAsync service gives you the benefits of asynchronous operation.

  • The ReportStorageWebExtension service is called when no other report name resolution services are available. It is designed to get reports from external storage (a file or a database) where they are saved in REPX format. You cannot apply parameters with this service because its GetData method returns a serialized report that is subsequently deserialized using a parameterless constructor.

Open Subreports

The XRSubreport control in a report defines an additional report (subreport) included in the host report. The control's ReportSource property specifies a 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 along with the main report. To open a subreport, the Document Viewer passes the XRSubreport.ReportSourceUrl property value to the available report name resolution services, except the following:

Consider a reporting application in which both IWebDocumentViewerReportResolver and IReportProvider services are available. When the Document Viewer opens a report that contains a subreport, the IWebDocumentViewerReportResolver service resolves the main report name while the IReportProvider service is called to resolve the subreport name.