0
私のASP.NETのWeb APIクラスは、URIからフィルタクラスにマッピングされているフィルタの様々なを持っていGETエンドポイントを持っているウェブAPIモデルバインドCSV
public IHttpActionResult List([FromUri] FilterModel filter)
Filterクラス:
public class FilterModel {
public int Something {get;set;}
public int[] UserIds {get;set;}
...lots of other properties...
}
私は、ユーザーIDは、カンマ区切りリストとして渡すことがしたいと思います:
http://foo.com/api/things?UserIds=1,2,3
しかし、この中のWeb API、それは期待し:
http://foo.com/api/things?UserIds=1&UserIds=2&UserIds=3
は、この問題を解決するための簡単な方法があります。私はカスタムモデルバインダーを作成することができますが、モデルバインディングの99%は何も変更したくありません。私の理想的な解決策は次のようなものでしょう:
public class CustomModelBinder : IModelBinder
{
public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext)
{
// Access the "default" model that's created from the Uri params
var model = ???
// Then do some work to bind the UserIds
return true;
}
}
アイデアはありますか?
おかげ
カスタムメディアタイプフォーマッタを作成する必要があります。例:[link](http://stackoverflow.com/questions/15633402/csv-media-type-formatter-for-asp-net-web-api) –