I have a requirement to bind an entity of type ‘Field’ which has a List as a property. The list will have mixed types of behaviour, but all inherit from Behaviour. I need the list to bind with the correct derived types so they can be persisted correctly.
I am using a technique used in the DerivedTypesModelBinder in the MvcContrib library, whereby I have a property on each of my entities which holds the type that needs to be created. The field is called ‘XxModelTypexX’.
My problem is, I am not sure how to change the type of a property in a custom model binder. Every time I try it simply binds a generic list of Behaviours.
Any help would be appreciated.
Ok, so I figured it out. Basically even though the list of Behaviour is a property on Field, you still have to add that to the list of types that use the custom model binder in the Global.asax file
With this line in place the type changing code I had worked a treat.