model view controller - C# 4.0 Generics and ASP.net MVC -


it appears in c# 4.0, variance specifiers applicable interface types.

so let's have viewmodel / editmodel classes , simple hierarchy of models.

class myeditmodel<t> t : base { ... } class derived1 : base { ... } class derived2 : base { ... } 

i have partial view accepts myeditmodel of type (so long it's derived base) , 1 accepts instances of derived1. how render both on same page?

the partial view accepts myeditmodel shared between editor derived1 , editor derived2.

the has if view accept view model of base. oo perspective myeditmodel , derived1 share base common base class - don't share else - there no other relationship. hence, if you're trying use same have derive base. presumably properties on base ones have in common.

edit: mis-interpreted original question. based on literal text of question, thought passing derived1 base on comment below passing myeditmodel<derived1>. you're seeking:

inherits="system.web.mvc.viewpage<dynamic>  

you don't benefit of intellisense dynamic - benefit of reusing same view file types , benefit of not having create view model classes make compiler happy.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -