public static string CustomRazorViewRender(object dataModel, string viewPath)
{
var streamWriter = new StringWriter();
var httpContextWrapper = new HttpContextWrapper(System.Web.HttpContext.Current);
var customRouteData = new RouteData() ;
CustomHomeController controllerInstance= new CustomHomeController();
var customControllerContext = new ControllerContext(new RequestContext(httpContextWrapper, customRouteData), controllerInstance);
var customRazorView = new RazorView(customControllerContext, viewPath, null, false, null);
customRazorView.Render(new ViewContext(customControllerContext, customRazorView, new ViewDataDictionary(dataModel), new TempDataDictionary(), streamWriter), streamWriter);
return streamWriter.ToString();
}
within this code snippet, the
Razor.render
line is causing an error:
'The RouteData must contain an item named 'controller' with a non-empty string value.'
I suspect that it cannot locate my custom homecontroller because my project includes areas. How should I go about resolving this issue?