尝试使用示例http://weblog.west-wind.com/posts/2012/May/30/Rendering-ASPNET-MVC-Views-to-String
将 VIEW 作为字符串传递,并作为电子邮件发送。哪个应该通过电子邮件将销售发票发送给用户。
我已将 ViewRenderer 类添加到我的项目中。然后将 ContactSeller 函数添加到我的控制器中,并将发票视图复制并重命名为ViewOrderThroughEmail.cshtml
[HttpPost]
[AlwaysAccessible]
public ActionResult SendEmailAttachment(QBCustomerRecord cust)
{
ContactSellerViewModel model = new ContactSellerViewModel();
string invoiceEmailAsString = ContactSeller(model);
_userService.SendEmail(username, nonce => Url.MakeAbsolute(Url.Action("LostPassword", "Account", new { Area = "Orchard.Users", nonce = nonce }), siteUrl), invoiceEmailAsString);
_orchardServices.Notifier.Information(T("The user will receive a confirmation link through email."));
return RedirectToAction("LogOn");
}
[HttpPost]
public string ContactSeller(ContactSellerViewModel model)
{
string message = ViewRenderer.RenderView("~/Orchard.Web/Modules/RainBow/Views/Account/ViewOrderThroughEmail.cshtml",model,
ControllerContext);
model.EntryId = 101;
model.EntryTitle = message;
return message;
}
但这会引发错误,VIEW 不能为 NULL:
using (var sw = new StringWriter())
{
var ctx = new ViewContext(Context, view,
Context.Controller.ViewData,
Context.Controller.TempData,
sw);
view.Render(ctx, sw);
result = sw.ToString();
}
在RenderViewToStringInternal
ViewRenderer.cs 的函数中。我原本以为这是视图的路径,但事实并非如此。
有任何想法吗?谢谢