Support for generics in razor view
It would be great if razor views could support generic models.
This request is now being tracked on GitHub at https://github.com/aspnet/mvc/issues/727.
It would be helpful if folks could comment on the GitHub issue with specific use cases for when you would want to use an open generic for you view model type. We are trying to get a better feel for the relevant scenarios. Thanks!
@Daniel Roth closed generics are great and in most cases are enough (for me) but there are several cases that you really needs an open generic and I think this kind of framework should have a nice answer for that need.
Pablo A. Revert commented
It would be great to have open generics!!!
Joy Roychowdhury commented
This is much needed creating a generic type of View which is common . That could ease a lot of scenarios
Martijn Hoekstra commented
This is especially useful for me for number types that don't share a common supertype (int, float, decimal, double, long, byte) and want to keep generic in the model, but use the same view for
Nico Sap commented
If i'm not mistaking, i used dynamic once in my views.
That could solve the problem, doesn't it? :)
This request is about open generics.
We currently support closed generics. Is that sufficient? Or is the request here specifically about open generics?
Tom Potts commented
It should support the where keyword too, either within the model statement or in a separate directive. For example,
@model IEnumerable<T> where T : MyBaseClass
Yes, it's really important feature.
At least support this for layouts.