I am trying to generate emails with HTML content. this content has already gone through sanitation so I am not worried in that regard, however when I call:
If you have a custom base class for your templates, you can code Write
method to behave similar to normal MVC template: if the output value is IHtmlString
it should not encode it.
Here's the code I'm using in my TemplateBase
class:
// Writes the results of expressions like: "@foo.Bar"
public virtual void Write(object value)
{
if (value is IHtmlString)
WriteLiteral(value);
else
WriteLiteral(AntiXssEncoder.HtmlEncode(value.ToString(), false));
}
// Writes literals like markup: "Foo
"
public virtual void WriteLiteral(object value)
{
Buffer.Append(value);
}