我正在尝试在 Web api 上使用 MvcMailer,但我被卡住了!!!我收到以下错误。我认为这与usermailer和view之间的路由有关。我看到它找不到视图,但我可能是错的。任何帮助将不胜感激。
谢谢
错误:
Value cannot be null.Parameter name: routeData
堆栈跟踪:
at System.Web.Routing.RequestContext..ctor(HttpContextBase httpContext, RouteData routeData)
at System.Web.Mvc.ControllerContext..ctor(HttpContextBase httpContext, RouteData routeData, ControllerBase controller)
at Mvc.Mailer.MailerBase.CreateControllerContext()
at Mvc.Mailer.MailerBase.ViewExists(String viewName, String masterName)
at Mvc.Mailer.MailerBase.TextViewExists(String viewName, String masterName)
at Mvc.Mailer.MailerBase.PopulateBody(MailMessage mailMessage, String viewName, String masterName, Dictionary`2 linkedResources)
at Mvc.Mailer.MailerBase.Populate(Action`1 action)
at App.Api.Mailers.UserMailer.NewCandidate() in e:\VS2013 Projects\App.Api\Mailers\UserMailer.cs:line 15
at App.Api.Controllers.CandidatesController.Get() in e:\VS2013 Projects\App.Api\Controllers\CandidatesController.cs:line 31
控制器:
private readonly UserMailer _mailer = new UserMailer();
[Authorize]
[Route("")]
[HttpPost]
// POST api/requests
public HttpResponseMessage Post(Candidate candidate)
{
_repository.CandidateRepository.Insert(candidate);
_repository.Save();
_mailer.NewCandidate().Send();
return Request.CreateResponse(HttpStatusCode.OK, candidate);
}
用户邮件类:
public class UserMailer : MailerBase, IUserMailer
{
public UserMailer()
{
MasterName="_Layout";
}
public virtual MvcMailMessage NewCandidate()
{
//ViewBag.Data = someObject;
return Populate(x =>
{
x.Subject = "NewCandidate";
x.ViewName = "NewCandidate";
x.To.Add("test@test.test");
});
}
}
文件夹结构:
谢谢