2012-08-20 13 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

相关问题