あきらめる前にたどり着かなかったこの質問のために開いたタブを閉じていると、誰かが答えを見つけました。ModelBinderAttribute
ビュー モデルに を割り当てることができます。
[ModelBinder(typeof(SomeEditorModelModelBinder))]
public class SomeEditorModel {
// display model goes here
}
public class SomeEditorModelModelBinder : DefaultModelBinder {
// custom model binder for said model goes here
}
私が探していたものとはまったく異なりましたが、コントローラーまたはコントローラーメソッドに登録するよりもさらに具体的です。
アップデート
より良い解決策を指摘してくれた Levi のコメントに感謝します。MVC アクション メソッドでカスタム モデル バインダーを使用してオブジェクトを直接使用する場合は、そのメソッドのパラメーターをModelBinder
プロパティで単純に装飾できます。
public ActionResult SomeMethod([ModelBinder(typeof(SomeEditorModelBinder))]SomeEditorModel model) { ... }