A more elegant solution is to build an extension method:
using Microsoft.AspNetCore.Html;
public static class StringExtensions
{
///
/// Convert a standard string into a htmlstring for rendering in a view
///
///
///
public static HtmlString ToHtmlString(this string value)
{
return new HtmlString(value);
}
}
In your _ViewImports file, include the namespace if required:
@using MyProject.Extensions
Now in your views you will be able to do:
@Model.ReportHTML.ToHtmlString()
I'd advise doing additional sanitization in a real world app but this should answer the OP's question.