0

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) {}
tereško
  • 58,060
  • 25
  • 98
  • 150
Dested
  • 6,294
  • 12
  • 51
  • 73
  • How do you determine which concrete type must be deserialized into the base class (SomeObject or AnotherObject) ?. You could write a custom MediaTypeFormatter or ModelBinder, but you need to determine the type somehow. – Pablo Cibraro May 07 '13 at 20:01

1 Answers1

1

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

WebApi Model Binding For Inherited Types

Community
  • 1
  • 1
Kiran
  • 56,921
  • 15
  • 176
  • 161