Here is my custom middleware that is used to create the derived class.
public class LocationModalBinder : DefaultModelBinder { protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) { var type = bindingContext.ModelName + "." + "type"; Type typeToInstantiate; switch ((string) bindingContext.ValueProvider.GetValue(type).RawValue) { case "store": { typeToInstantiate = typeof (Store); break; } case "billing": { typeToInstantiate = typeof(LocationReference); break; } case "alternate": { typeToInstantiate = typeof(Address); break; } default: { throw new Exception("Unknown location identifier."); } } return base.CreateModel(controllerContext, bindingContext, typeToInstantiate); } }
The problem is that it does not bind properties in a subtype. Only properties of the base type Location . Why is this?
source share