I’m attempting to use RazorEngine 3 to insert HTML elements into a template. When I try this, the resulting string (used later as HTML) ends up displaying the HTML markup rather than utilizing it to render the page.
Code:
var linkText = new HtmlString("<a href=" + location + ">" + linkName + "</a>");
string result = Razor.Parse(template, new {MyLink = linkText});
Template file:
Link to file: @Model.MyLink
Resulting HTML:
Link to file: <a href=http://blah.com>Blah link</a>
This functionality was working fine with RazorEngine 2, but I had to upgrade due to another glitch. Additionally, this is a console application so adding @Raw functionality might be complicated.
The answer ended up being to use a string type variable that is passed into the template. The template, in turn uses the Raw() method as seen below.
Code:
Template File: