question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Email template not rendering model data

See original GitHub issue

This may be me missing something really obvious, but I am not able to replace the @Model.Strings components in my email template properly. I am using the latest version of .NET Core on a new project.

Here is my controller code starting the email send off.

            Email.DefaultRenderer = new RazorRenderer();
            Email.DefaultSender = new SendGridSender("KEY");
            var email = Email
                .From("do-not-reply@company.io", "Company")
                .To(model.Email)
                .Subject("You have been invited to join " + company.Name + "!")
                .UsingTemplateFromFile($"{Directory.GetCurrentDirectory()}/Views/Emails/StandardEmail.cshtml", new {
                    CallbackUrl = callbackUrl,
                    ButtonText = buttonText,
                    Footer = footer,
                    Body = body,
                    Header = header
                });
            await email.SendAsync();

Then my email file has several @Model.Footer and based on what is seen above. I am not using any other special code in the email file besides the HTML.

The email properly sends as expected, but I receive the email with the @Model.Footer text being shown, instead of the data being passed in the model above.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

3reactions
piusncommented, Feb 14, 2018

Please ensure you adding this line of code

// Using Razor templating package Email.DefaultRenderer = new RazorRenderer();

At your start up. This should work

0reactions
etheringtoncommented, Jan 16, 2018

I’m having the same problem.

<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>WelcomeEmail</title> </head> <body> <div>

Listee


<dl class="dl-horizontal"> <dt> FirstName </dt> <dd> @Model.FirstName </dd> <dt> LastName </dt> <dd> @Model.LastName </dd> <dt> EmailAddress </dt> <dd> @Model.EmailAddress </dd> </dl> </div> </body> </html>
Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML email template is not rendering correctly
And when it comes to rendering in a web browser it looks just fine, but I open such email in the Outlook app...
Read more >
How to render email template objects in custom module?
Hello I made a custom module that load data from email.template but the problem is that data not rendering and just showing as...
Read more >
Email content not rendering when Pass custom relatedTo ...
I have tried to test with merge field in email template with EnvironmentId and contact, it works. Seems either the template is not...
Read more >
Visualforce Email template is not rendering and it shows ...
Hello everyone, I have created a visualforce Email template that uses a visualforce component to display some records in a form of a...
Read more >
Php Template not rendering when sent in email
Currently the email gets sent but the template does not get rendered. ... Render view template public function render( $file, $data = false...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found