2012-08-20 14 views
1

我得到的錯誤,當我嘗試發送電子郵件:在VB傳送電子郵件與ActionMailer.Mvc,找不到查看

Return Email("~/Views/Email/VerificationEmail.html.vbhtml", model)

可以:

NoViewsFoundException

You must provide a view for this email. Views should be named ~/Views/Email/VerificationEmail.html.vbhtml.txt.cshtml or ~/Views/Email/VerificationEmail.html.vbhtml.html.cshtml (or aspx for WebFormsViewEngine) depending on the format you wish to render.

上線錯誤電子郵件不會以.vbhtml發送,它們必須以.cshtml發送嗎?這對VB如何工作?

這裏是我的代碼控制器:

Imports ActionMailer.Net.Mvc 

Public Class EmailController 
    Inherits MailerBase 

    Public Function VerificationEmail(ByVal model As RegisterModel) As EmailResult 

     [To].Add(model.Email) 
     From = "[email protected]" 
     Subject = "Thanks for registering with us!" 
     Return Email("~/Views/Email/VerificationEmail.html.vbhtml", model) 

    End Function 

End Class 

這是我的觀點:

@modelType MyBlog.RegisterModel 

@Code 
    Layout = Nothing 
End code 

Welcome to My Cool Site, @Model.UserName 

We need you to verify your email. Click this nifty link to get verified! 

@Html.ActionLink("Verify", "Account", New With {.code = Model.Email}) 

Thanks! 

回答

2

當然,你可以有你只需要小心的命名vbhtml電子郵件模板(在.cshtml s的例外信息是硬編碼的,所以不要混淆)

你的觀點被正確命名爲VerificationEmail.html.vbhtml你只需要從視圖名稱中刪除所有的前綴在Email電話:

Return Email("VerificationEmail", model) 

因爲,ActionMailer會自動添加前綴,並選擇正確的模板爲您服務。

請注意,當前不能使用相對視圖名稱,例如以~開頭的相對視圖名稱,例如, "~/Views/..."(我不知道這是一個錯誤還是功能)。

因此,您需要將您的郵件模板放置在常規視圖文件夾中,例如

  • /Views/{MailControllerName}/
  • /View/Shared/
+0

我改變你的代碼,但我仍然得到錯誤:'你必須提供此電子郵件的視圖。根據您想要渲染的格式,視圖應該被命名爲〜/ Views/Email/VerificationEmail.txt.cshtml或〜/ Views/Email/VerificationEmail.html.cshtml(或aspx for WebFormsViewEngine)。 – user1477388

+0

您可以幫忙嗎?我必須刪除並重新發布更多信息嗎?謝謝。 – user1477388

+1

@ user1477388我已經設法重製你的問題,在ActionMailer中肯定有錯誤...沒有必要刪除你的問題,這很好。如果我找到了某些東西,我會更新我的答案。 – nemesv

4

讀一對夫婦的問題和答案後,能得到它的這項工作:

public override string ViewPath { 
     get { return AppDomain.CurrentDomain.BaseDirectory + @"\EmailTemplates\"; } 
    } 
+0

謝謝,這是停止我的代碼工作。非常感激。 – Haroon

1

有同樣的問題,因爲乍得 - 理查德森。爲了解決這恰好試圖從其他地區發送電子郵件時,只需將此代碼添加到Application_Start方法中的問題:

var razorEngine = ViewEngines.Engines.OfType<RazorViewEngine>().First(); 
    razorEngine.ViewLocationFormats = razorEngine.ViewLocationFormats.Concat(new string[] 
    { 
     "~/Areas/.../{0}.cshtml" 
    }).ToArray(); 
+0

感謝您的信息 – user1477388

相關問題