[英]WebAPI Custom ModelBinder inheritance
我正在尝试使用WebAPI BindParameter绑定到某个对象类型的父级。 我能够绑定到对象本身(SomeObject),但不能绑定到其父对象(SomeOtherObject)。 这将导致我必须对SomeObject的所有可能的继承者进行特定的BindParameter调用。 有没有更好的方法来绑定参数类型,使我能够完成此任务?
粘合剂:
GlobalConfiguration.Configuration.BindParameter(typeof(SomeObject), new SetTrackerModelBinder());
GlobalConfiguration.Configuration.BindParameter(typeof(SomeOtherObject), new SetTrackerModelBinder()); //Does not work.
对象结构:
public class SomeObject:SomeOtherObject{
}
public class AnotherObject:SomeOtherObject{
}
public class SomeOtherObject{
}
那个行动:
public void PostStuffs(SomeObject value) {}
您可以尝试查看我对以下帖子的回答。 我不使用ModelBinders:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.