Dested
Dested

Reputation: 6433

WebAPI Custom ModelBinder inheritance

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) {}

Upvotes: 0

Views: 690

Answers (1)

Kiran
Kiran

Reputation: 57949

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

WebApi Model Binding For Inherited Types

Upvotes: 1

Related Questions