我想在我的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