Add custom Model Binders for derived objects and their base
- by mare
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.