Search code examples
asp.net-mvcrazorengine

Generate html in body with RazorEngine email template


I'm using RazorEngine to generate an email with a template.

The issue I'm having is I cannot add a line break in the email body.

var model = new EmailModel
        {
            Destination = "anon@gmail.com",
            Subject = "Some Subject",
            Body = "Hello <br> Break <br> it <br> up"
        };

var service = TemplateManager.RazorService;
var htmlBody = service.RunCompile("EmailTemplate.cshtml", model.GetType(), model);
await EmailService.SendEmail(model.Destination, model.Subject, htmlBody);

I tried doing the following in my Template:

@Html.Raw(Model.Body)

But it still won't decode the html, any ideas?


Solution

  • UPDATE:

    The solution has been found here: https://github.com/Antaris/RazorEngine/issues/34

    And here: RazorEngine: cannot use Html.Raw

    It's enough to use @(new RawString("html string here")) or @Raw("html string here") instead of @Html.Raw("html string here").