Model Binder doesnt bind properties of derived classes

I have a custom Model Binder that binds a list of BaseClass objects. BaseClass is abstract, list contains derived objects of different types.
When binding the model, ValueProvider.GetValue for properties of derived classes returns empty and these properties are not bound.
Do i need some extra setup to be able to access these properties?

I set up a key:

var modelOptionsKey = ModelNames.CreatePropertyModelName(indexKey, nameof(MultipleChoiceQDTO.Options));

and a ValueProviderResult:

var modelOptionsValueProviderResult = bindingContext.ValueProvider.GetValue(modelOptionsKey).Values.ToList()

I expected to get a list, containing values from the RazorPage, but instead the list is empty.
Same goes for a regular string property.

Leave a Comment