3
尝试使用http://weblog.west-wind.com/posts/2012/May/30/Rendering-ASPNET-MVC-Views-to-String
上的示例将VIEW作为字符串传递,并作为电子邮件发送。应该通过电子邮件将销售发票发送给用户。传递VIEW作为STRING
Iv'e将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
功能
的.cs。我一直认为这是观点的道路,但不是。
任何想法? 感谢