問題タブ [modelbinder]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票する
1 に答える
180 参照

c# - ModelBinder からカスタム InputFormatter へのデータの受け渡し

コンテキスト: Asp.net Core 2.1のWebAPI では、POST エンドポイントを作成する必要があります [server]/MyController/{Parameter1}/MoreRouteThing/IInputFormatterデフォルトのフォーマッタでは本文を読み取れないため、カスタムを作成する必要があります。

問題: 入力をフォーマットできるようにするにはIInputFormatter、 の値を知る必要がありますParameter1

IModelBinderこのモデルを処理するカスタムを実装し、カスタムをstartup.cs使用してすべてを配線しましたIModelBinderProvider(おそらくやり過ぎですが、チェーン全体を理解したかったのです)。

custom 内では、似たようなものを使用してIModelBinderアクセスできますが、それを に渡す方法がわかりません。前者は後者に を渡しますが、そのコンテキスト オブジェクト内には追加情報を格納するのに適切なものはないようです。{Parameter1}bindingContext.ActionContext.RouteData.Values["Parameter1"]IInputFormatterInputFormatterContext

質問: から にデータを渡す方法IModelBinderは? IInputFormatter代わりに から直接 url/route を解析する必要があるIInputFormatterため、プロセス全体の「どこ」にあるかを認識できますか? (私には不潔に思えます。)