Skip to content
Report-Designer

ASP.NET MVC 5

Configure ReportHost in a .NET Framework 4.8 app and return a report from a controller.

Reference ReportDesigner.Runtime. In a classic project, you can reference the engine’s net48 build output. Keep AutoGenerateBindingRedirects enabled so Web.config gets the redirects for the engine’s dependencies. See the download page for the package feed.

Configure ReportHost once in Application_Start in Global.asax.cs.

ReportHost.Configure(options =>
{
    options.ReportsPath = Server.MapPath("~/Reports");
    options.Connections["Sales"] = ConfigurationManager.ConnectionStrings["Sales"].ConnectionString;
});

For a report project, set ProjectPath to the project folder in place of ReportsPath. The report refers to Sales by name. The connection string stays in Web.config.

Render a report

Call ReportHost.Reports.RenderAsync in your controller.

public async Task<ActionResult> Sales(DateTime from, DateTime to)
{
    var pdf = await ReportHost.Reports.RenderAsync("sales-summary", new { FromDate = from, ToDate = to });
    return File(pdf, "application/pdf");
}

You can also pass Request.QueryString when its keys match the report’s parameter names, such as FromDate and ToDate. To render over HTTP, set Server.Url, Server.Project and Server.ApiKey in ReportHost.Configure. See Report server.