Created
January 18, 2018 09:21
-
-
Save shturm/0c53dc495b3aff8148bd6f6d4ba5fd47 to your computer and use it in GitHub Desktop.
Render Razor For Email/Page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected string GetRenderedPartial(string viewName, object model = null) | |
{ | |
using (var sw = new StringWriter()) | |
{ | |
if (ControllerContext != null) | |
{ | |
var viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName); | |
var viewContext = new ViewContext(ControllerContext, viewResult.View, new ViewDataDictionary(model), TempData, sw); | |
viewResult.View.Render(viewContext, sw); | |
} | |
return sw.ToString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment