mortenstarck
mortenstarck

Reputation: 2803

Razorenginen Not loading View

I'm using razorengine to send emails. The senden is not the problem, but the content is only displayed as /da/Property/Property/Mail/TellAFriendTextMail in the content.

private void SendTellAFriendMail(NotificationTellAFriend mailData)
    {

      string textmail = this.GetMailAsText(mailData);
      string htmlmail = this.GetMailAsHTML(mailData);

      MailAddress from = new MailAddress("[email protected]", mailData.SenderName);
      MailAddress to = new MailAddress(mailData.receiverMail, mailData.SenderName);

      using (AlternateView htmlview = this.CreateView(htmlmail, "text/html"))
      using (AlternateView textview = this.CreateView(textmail, "text/plain"))
      using (MailMessage email = new MailMessage(from, to))
      {
        email.Subject = string.Format(CultureInfo.InvariantCulture, Resources.Resources._MailSubject, mailData.SenderName);
        email.AlternateViews.Add(textview);
        email.AlternateViews.Add(htmlview);
        email.ReplyToList.Add(new MailAddress(mailData.receiverMail, mailData.SenderName));

        using (SmtpClient client = new SmtpClient())
        {
          client.Send(email);
        }

      }
    }

 private string GetMailAsHTML(NotificationTellAFriend mailData)
    {
      return Razor.Parse(Url.Action("/Property/Mail/TellAFriendTextMail"), mailData);
    }

Upvotes: 0

Views: 67

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038720

The first argument of the Razor.Parse method is not an url but the actual Razor contents that you want to be parsed. So:

private string GetMailAsHTML(NotificationTellAFriend mailData)
{
    var razorTemplateFile = Server.MapPath("~/Property/Mail/TellAFriendTextMail.cshtml");
    var razorTemplate = File.ReadAllText(razorTemplateFile);
    return Razor.Parse(razorTemplate, mailData);
}

Upvotes: 1

Related Questions