Attempting to use the example on http://weblog.west-wind.com/posts/2012/May/30/Rendering-ASPNET-MVC-Views-to-String
to pass a VIEW as a string, and send as an Email. Which should send the invoice of a sale through email to the user.
Iv'e added ViewRenderer class to my project. Then added the ContactSeller function to my controller, and copied and renamed the invoice view as 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;
}
but this throws a error, VIEW cant be 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();
}
in the RenderViewToStringInternal
function in the ViewRenderer.cs. I oringally thought it was the path of the view, but its not.
Any ideas? Thanks
I use the following extension method in my projects:
Then in your action method: