I was using a piece of code to send templated emails which the body is contained in a .cshtml file.
Basically the code takes an html template in the chtml file and smooshes it with the model values to create custom email to send - like a custom greeting. I had to also insert a custom closing that may or may not contain html. I attempted to use @Html.Raw(@Model.Closing) but it would throw some unknown exception and then subsequently not send the email. It was quite difficult to debug because it was hard to debug the razor form with how the call was being made.
Anyhow, after several hours, I found I should just use @Raw(@Model.Closing) rather than @Html.Raw(@Model.Closing). This was advice that was given however it was tricky because in Visual Studio the little red squiggly line says that is going to be a problem....but that was in fact not true it worked:
Here is a sample of what was in the .cshmtl file:
- @model Junk.Mail.TemplatesModels.EmailModel
- <html>
- <body>
- <p>
- Hello @Model.Name
- </p>
- <p>
- Blah blha blah blah
- </p>
- <p>
- Thank you for your attention.
- </p>
- @Raw(@Model.Closing)
- </body>
- </html>
@model Junk.Mail.TemplatesModels.EmailModel
<html>
<body>
<p>
Hello @Model.Name
</p>
<p>
Blah blha blah blah
</p>
<p>
Thank you for your attention.
</p>
@Raw(@Model.Closing)
</body>
</html>
Hope that helps.