0

Razor does not work in html email template; This produces the image:

*<img style="border: 0;-ms-interpolation-mode: bicubic;display: block;max-width: 600px" src="http://xxx.xx.uk/off-line/email-template-images/banner.jpg" alt="http://xxxx.xx.uk/off-line/email-template-images/banner.jpg" width="600" height="229">*

This does not:

*<img style="border: 0;-ms-interpolation-mode: bicubic;display: block;max-width: 600px" src="@ViewBag.imageurl" alt="http://xxxx.xx.uk/off-line/email-template-images/banner.jpg" width="600" height="229">*

Note razor in SRC. How can I render the image using a reference from the controller?

3
  • Check out aboutcode.net/postal. Commented Sep 17, 2015 at 13:23
  • Thanks, I am using Postal MVC, but src="@ViewBag.imageurl" does not work. Commented Sep 18, 2015 at 13:38
  • Postal doesn't have a ViewBag. The whole point is to pass a strongly-typed Email subclass to the view with whatever data you need on it. Commented Sep 18, 2015 at 14:44

1 Answer 1

1

I would strongly suggest that you use RazorEngine for this task. It allows you to use Razor outside of MVC. There is a tutorial here.

An example might be:

string email = "Hello @Model.Name! Thanks for registering.";
string body = Razor.Parse(email, new { Name = "Bob Smith" });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.