2013-01-11 77 views
0

我正在使用razorengine發送電子郵件。 senden不是問題,但內容僅在內容中顯示爲/ da/Property/Property/Mail/TellAFriendTextMail。Razorenginen未加載查看

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); 
    } 

回答

1

Razor.Parse方法的第一個參數是不是一個URL,但要解析的實際剃刀內容。所以:

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

它給我這個錯誤 「找不到路徑的一部分。 'd:\顛覆\ Oline \ Oline.Portal \來源\ Oline.Portal \地產\郵件\ TellAFriendTextMail.cshtml'」 – mortenstarck

+0

那麼你究竟期待我說什麼?修復您的路徑,使其指向現有的Razor模板。 –

+0

那麼路徑是「Server.MapPath(」〜/ Property/Mail/TellAFriendTextMail.cshtml「 – mortenstarck