WebAPI Custom ModelBinder inheritance

701 Views Asked by At

I am trying to bind to the parent of a certain object type using WebAPI BindParameter. I am able to bind to the object itself (SomeObject), but not its parent (SomeOtherObject). This would cause me to have to have a specific BindParameter call for all possible inheritors of SomeObject. Is there a better way to bind the parameter type that would allow me to accomplish this?

The binders:

GlobalConfiguration.Configuration.BindParameter(typeof(SomeObject), new SetTrackerModelBinder()); 

GlobalConfiguration.Configuration.BindParameter(typeof(SomeOtherObject), new SetTrackerModelBinder()); //Does not work. 

The object structure:

public class SomeObject:SomeOtherObject{

}
public class AnotherObject:SomeOtherObject{

}
public class SomeOtherObject{

}

The action:

public void PostStuffs(SomeObject value) {}
1

There are 1 best solutions below

0
On

You can try looking at my answer to the following post. I do not use ModelBinders though:

WebApi Model Binding For Inherited Types