簡體   English   中英

WebAPI自定義ModelBinder繼承

[英]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:

繼承類型的WebApi模型綁定

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM