0

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?

tqrecords
  • 542
  • 1
  • 5
  • 20

2 Answers2

1

Your <br> tag in the Body is incorrect.

Replace <br> with <br />

O. Shai
  • 703
  • 7
  • 22
0

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").

tqrecords
  • 542
  • 1
  • 5
  • 20