I am working on an ASP.Net MVC website and I am fixated on getting C # code using generics to play well with my views.
I have a controller that passes the model into a view (so far so good). The model has a type IDescribedEnumerable<T>with some restrictions on T, among which there is a restriction that Tinherits from the interface ( IDescribedModel).
I can easily write a view that accepts IDescribedEnumerable<Country>, and it will work as long as it Tis actually a type Country.
However, I would also like to write a default view that accepts IDescribedEnumerableof <<whatever>>and will display it. This should be completely possible. I do not always need to know the specific type of Model. Often just knowing that is enough IDescribedModel.
As long as I stay in C #, there are no problems. When I do not need a specific type, I simply declare the methods and objects as accepting <T>. When I don't care, I declare them accepted Country.
But:
(1) If I want to display the view, I have to choose the type. I can't just say Inherits="System.Web.Mvc.ViewUserControl<IDescribedEnumerable<T>>"I need to specify an existing type between <>. (even if I inherited from ViewUserControl, I would have to send it to IDescribedEnumerable<<something>>. (2) Ideally, I would say that Model IDescribedEnumerable<IDescribedModel>is in the default view and IDescribedEnumerable<Country>in the specific implementation. However, then my controller should know if it will be displayed in the default view or a specific view. It is not possible to just select an object from IDescribedEnumerable<Country>to IDescribedEnumerable<IDescribedModel>. (IIRC is possible in C # 4, but I use 3.5)
? , , ( , 65 , Type)