Add custom Model Binders for derived objects and their base
Posted
by mare
on Stack Overflow
See other posts from Stack Overflow
or by mare
Published on 2010-04-06T14:21:43Z
Indexed on
2010/04/06
14:23 UTC
Read the original article
Hit count: 311
asp.net-mvc
|modelbi
My class diagram:
BaseContentClass
- Page inherits BaseContentClass
- Tab inherits BaseContentClass
- ...
If I do this
ModelBinders.Binders.Add(typeof(BaseContentObject), new BaseContentObjectCommonPropertiesBinder());
then when in controller action parameter of type Tab appears, custom model binder is not fired.
It gets fired if I do this:
ModelBinders.Binders.Add(typeof(Tab), new BaseContentObjectCommonPropertiesBinder());
But I don't want to go writing "n" number of Add statements in my global.asax.cs to associate all the derived classes with my custom model binder, do I? I don't know if I have any other option.
© Stack Overflow or respective owner