I read this very helpful post: how to render html to a string instead of to the screen in MVC3.
I've created a function that does just that in my controller. I would now like to be able to call this method from class in another project so that I can offer this function as a service. The code looks like this:
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();
}
I'd like to call this class directly and not via the IIS. But then the ControllerContext is null. Can I specify the View on disc somehow?