Skip to content

Instantly share code, notes, and snippets.

@bergquist
Created March 7, 2013 13:02
Show Gist options
  • Save bergquist/5107905 to your computer and use it in GitHub Desktop.
Save bergquist/5107905 to your computer and use it in GitHub Desktop.
Render razorviews as strings.
using (var sw = new StringWriter()) {
ViewEngineResult viewEngineResult = ViewEngines.Engines.FindPartialView(controllerContext, viewName);
var viewContext = new ViewContext(controllerContext, viewEngineResult.View, viewData, new TempDataDictionary(), sw);
viewEngineResult.View.Render(viewContext, sw);
return sw.GetStringBuilder().ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment