Skip to content

Instantly share code, notes, and snippets.

@jackinf
Created October 17, 2014 07:45
Show Gist options
  • Save jackinf/2785bd945fca21b4a840 to your computer and use it in GitHub Desktop.
Save jackinf/2785bd945fca21b4a840 to your computer and use it in GitHub Desktop.
EO PFD
// Konverdib partial Razor view to string
public string RenderRazorViewToString(string viewName, object model)
{
ViewData.Model = model;
using (var sw = new StringWriter())
{
var viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
var viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
viewResult.View.Render(viewContext, sw);
viewResult.ViewEngine.ReleaseView(ControllerContext, viewResult.View);
return sw.GetStringBuilder().ToString();
}
}
RenderRazorViewToString("~/Views/Order/DisplayForEmailMessage.cshtml", model);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment