public string GetRazorViewAsString(string filePath, object model = null)
{
var resultString = new StringWriter();
var context = new HttpContextWrapper(HttpContext.Current);
var routeData = new RouteData();
var controllerContext = new ControllerContext(new RequestContext(context, routeData), new DummyController());
var razor = new RazorView(controllerContext, filePath, null, false, null);
razor.Render(new ViewContext(controllerContext, razor, new ViewDataDictionary(model), new TempDataDictionary(), resultString), resultString);
return resultString.ToString();
}
public class DummyController : Controller { }
Currently, we are using above code for generating HTML for a view. In that, view path is a virtual path.
Now, we are planning to move the views outside of the project. So keeping virtual path is not possible now.
Any help on getting HTML by taking the full path of the view.