Klicke hier für den deutschen Artikel.
Applies to
- ASP.NET Core MVC with Razor on .NET 8 or later
- Web Report Viewer
- The package examples refer to List & Label 31
Introduction
The classic HTML5Viewer is deprecated and has been replaced by the more modern Web Report Viewer (WRV). To migrate, register the WRV services, create a controller that provides List & Label and the repository, and embed the viewer in a Razor view.
Prerequisites
- An ASP.NET Core MVC application with Razor on .NET 8 or later
- A repository containing the List & Label project to be displayed
- A fully initialized
ListLabelinstance including licensing, data source and required options
For List & Label 31, the NuGet packages combit.ListLabel31 and combit.ListLabel31.Web are required.
Perform the migration
1. Register the Web Report Viewer
Add the required services to Program.cs:
var builder = WebApplication.CreateBuilder(args);
builder.Services
.AddControllersWithViews()
.AddNewtonsoftJson();
builder.Services.AddWebReportViewer();
Then register the middleware before the controller route:
var app = builder.Build();
app.UseStaticFiles();
app.UseRouting();
app.UseWebReportViewer();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();
This provides the required Web Report Viewer services and endpoints in the ASP.NET Core application.
2. Create the Web Report Viewer controller
Create a controller derived from WebReportViewerController:
using System.IO;
using combit.Reporting;
using combit.Reporting.Web.WebReportViewer;
using Microsoft.AspNetCore.Hosting;
namespace YourMvcApp.Controllers
{
public class MyWebReportViewerController : WebReportViewerController
{
private readonly IWebHostEnvironment _environment;
public MyWebReportViewerController(IWebHostEnvironment environment)
{
_environment = environment;
}
public override void OnProvideListLabel(
ProvideListLabelContext context)
{
ListLabel ll = DefaultSettings.GetListLabelInstance(
context.ProjectName,
DefaultSettings.GetBaseRepository());
string exportPath = Path.Combine(
_environment.ContentRootPath,
"App_Data",
"TempFiles");
Directory.CreateDirectory(exportPath);
context.ExportPath = exportPath;
context.NewInstance = ll;
}
public override void OnProvideRepository(
ProvideRepositoryContext context)
{
context.FileRepository = DefaultSettings.GetBaseRepository();
}
}
}
The controller provides the viewer with a fully configured ListLabel instance and the repository for each session. The methods DefaultSettings.GetListLabelInstance(...) and DefaultSettings.GetBaseRepository() represent the application-specific initialization.
3. Display the viewer in a Razor view
Embed the Web Report Viewer in the required Razor view:
@using combit.Reporting.Web
@using combit.Reporting.Web.WebReportViewer
@{
string repositoryId = "<MY_REPOSITORY_ID>";
var options = new WebReportViewerMVCOptions(repositoryId)
{
Title = "Web Report Viewer"
};
}
@Html.WebReportViewer(options)
Replace <MY_REPOSITORY_ID> with the ID of the project in the repository or provide it dynamically from the application.
4. Remove the old HTML5Viewer integration
Remove the previous integration only after the Web Report Viewer has been successfully integrated and also works. Then review and remove:
- HTML5Viewer calls in views or partial views
- controllers and routes that are no longer required
- HTML5Viewer-specific JavaScript and CSS files
- assemblies or NuGet dependencies that are no longer used
Validation
The migration is successful when:
- the Web Report Viewer loads without errors
- the required repository project is displayed
- navigation, parameters and required export functions work
- the browser console no longer shows HTML5Viewer resources or related errors