Reputation: 1216
I have a System.Web.Mvc.RazorView object which is strongly typed when in cshtml.
Can I get the model type from an instance of this class?
Upvotes: 1
Views: 1408
Reputation: 887857
This is possible.
Call BuildManager.GetCompiledType(view.ViewPath)
to get the type generated by compiling the view.
You can find the model type by checking the generic argument of the compiled type's base type (which should be WebViewPage<TModel>
)
Upvotes: 4
Reputation: 1039268
There's no way to get the model given only an instance of a System.Web.Mvc.RazorView
. It's available inside the RenderView
method which is passed a ViewContext
but from the outside you can't access it. But if you are inside a view you could use the Model
property.
Upvotes: 1