Trying to render a view to a string inside a bare-bones class. I referenced MVC. I'm looking at this example: https://gist.github.com/eralston/d68287b6634f963c09c7
The problem is, they are assuming this is within the context of an MVC project. I have to provide the dependencies for FindPartialView
. I've fiddled around with a bunch of options, here, and can't even get a compileable instance.
Here's one of my attempts. I even tried creating a controller, but I cant figure out how to set any of the options, and MVC controllers are instantiated by the front controller magically, so I don't know what to actually do to configure the controllerContext
and TempData
. Specifically, what comes to mind is, where can I set my document root?
var viewDataDictionary = new ViewDataDictionary();
var controllerContext = new ControllerContext()
{
};
viewDataDictionary.Model = model;
using (var sw = new StringWriter())
{
var viewResult = ViewEngines.Engines.FindPartialView(controllerContext, viewName);
var viewContext = new ViewContext(controllerContext, viewResult.View, viewDataDictionary, TempData, sw);
}