I'm manually creating a RazorView instance and manually rendering that view to my response output.
var errorController = new FakeErrorController();
var controllerContext =
new ControllerContext(httpApplication.Context.Request.RequestContext,
errorController);
var view = new RazorView(controllerContext, viewPath, null, false, null);
var viewModel = new ErrorViewModel
{
Exception = currentError
};
var tempData = new TempDataDictionary();
var viewContext = new ViewContext(controllerContext, view,
new ViewDataDictionary(viewModel), tempData,
httpApplication.Response.Output);
view.Render(viewContext, httpApplication.Response.Output);
Works fine.
But notice how I've hard-coded the ViewModel? I was wondering if it's possible to see if the RazorView has a strongly-typed ViewModel defined.
eg. @model SomeNamespace.Model.Foo
and then create a new type, based on that. Lets also assume that there is a parameterless, default constructor.
Is this possible?