Refactor your HTML report with RazorEngine
Introduction
For generating a report, we can try to write HTML code with C# and export it. After all, we don’t have controllers, models, and views in the C# application, do we?
However, there are few disadvantages for mixing the HTML code and C# code.
First, it’s hard to maintain. Your program will be bigger and bigger. Your team members are hard to realize it because you mix view and models. Second, it’s also hard to scale up your program. You have to take a part of the views and models even though you’re not writing an ASP .NET program.
RazorEngine is a templating engine built on Microsoft’s Razor parsing engine, It allows you to use Razor syntax to build dynamic templates. It means that we will be allowed to use models and views in the C# program.
Installation
Open the Nuget console and type the following command on it.
Install-Package RazorEngine
Install-Package Microsoft.AspNet.Razor
Initialization and configuration
Initial the RazorEngine and config it with the TemplateServiceConfiguration class.