我想在我的mvc网络应用程序中使用mvcmailer。当我在一个虚拟项目中使用它并继续维基中陈述的步骤时,它运行良好,我可以发送电子邮件。mvc3中使用mvcmailer
但是,当我试图将它集成到我的Web应用程序中时,它在“PopulateBody(mailMessage,viewName:”Welcome“);”指出它无法找到_Layout.text。 _Layout.text.cshtml和_Layout.cshtml与Welcome.cshtml一起存在于Usermailer文件夹中。
Usermailer代码
public class UserMailer : MailerBase, IUserMailer
{
public UserMailer():
base()
{
MasterName="_Layout";
}
public virtual MailMessage Welcome(string email, string validationUrl)
{
var mailMessage = new MailMessage{Subject = "Welcome to GiftSocial"};
mailMessage.To.Add(email);
ViewBag.Validationkey = validationUrl;
PopulateBody(mailMessage, viewName: "Welcome");
return mailMessage;
}
}
控制器代码
UserMailer.Welcome(电子邮件:model.Email,validationUrl:validationUrl)。发送();
复制异常详细信息:
System.Web.HttpException was unhandled by user code
Message=The layout page "_Layout.text" could not be found at the following path: "~/Views/UserMailer/_Layout.text".
Source=Mvc.Mailer
ErrorCode=-2147467259
WebEventCode=0
StackTrace:
at Mvc.Mailer.StringResult.ExecuteResult(ControllerContext context, String mailerName)
at Mvc.Mailer.MailerBase.EmailBody(String viewName, String masterName)
at Mvc.Mailer.MailerBase.PopulateTextBody(MailMessage mailMessage, String viewName, String masterName)
at Mvc.Mailer.MailerBase.PopulateBody(MailMessage mailMessage, String viewName, String masterName, Dictionary`2 linkedResources)
at MvcGiftSocial.Mailers.UserMailer.Welcome(String email, String validationUrl)
at MvcGiftSocial.Controllers.AccountController.Register(RegisterViewModel viewmodel, String returnUrl) in C:\Users\ASUS\Documents\Visual Studio 2010\Projects\GiftSocialAzureNew\MvcGiftSocial\Controllers\AccountController.cs:line 86
at lambda_method(Closure , ControllerBase , Object[])
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
InnerException:
我衷心感激,如果有人能告诉我,我做错了什么..
感谢 ARNAB
能否请您发表您的共享布局和 – 2011-10-13 13:45:51
我使用的是相同的_layout和Welcome.cshtml附带mvcmailer,我还没有改变任何东西您的视图和视图模型 – Arnab