Skip to content
Alexander edited this page Mar 18, 2020 · 11 revisions

By default, this implementation of Razor will not encode values to be HTML safe, you need to escape values by yourself

RazorEngine razorEngine = new RazorEngine();
RazorEngineCompiledTemplate template = razorEngine.Compile("Hello @Model.Name");

string result = template.Run(new
{
    Name = "<b>Test</b>"
});

Console.WriteLine(result);

will output

Hello <b>Test</b>

Clone this wiki locally