tqrecords
tqrecords

Reputation: 541

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 = "[email protected]",
            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?

Upvotes: 0

Views: 1291

Answers (2)

tqrecords
tqrecords

Reputation: 541

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

Upvotes: 0

O. Shai
O. Shai

Reputation: 813

Your <br> tag in the Body is incorrect.

Replace <br> with <br />

Upvotes: 1

Related Questions