public string RenderRazorViewToString(string viewName, object model
= null)
{
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();
}
}
Note:-
2nd Parameter is optional you may pass the model or not.
How to utilize click the link
http://dotnet-jigyasa.blogspot.com/2018/09/render-razor-view-to-string-and.html
http://dotnet-jigyasa.blogspot.com/2018/09/render-razor-view-to-string-and.html
No comments:
Post a Comment