0

1 つのパラメータを持つ標準の HTML フォーム POST リクエストがあります。

フォームデータ:

model:{"Id":"2901179e-553e-4c9c-8c5c-281822ff2d11","Name":"T1","Sessions":[{"Id":"","Type":5,"Version":null,"Name":"","BestLapPoints":null,"TimeOfDayMins":1080,"hours":18,"minutes":0,"MaxLaps":null,"DurationMins":null,"Description":"","Points":[]},{"Id":"","Type":7,"Version":null,"Name":"","BestLapPoints":null,"TimeOfDayMins":1200,"hours":20,"minutes":0,"MaxLaps":null,"DurationMins":null,"Description":"","Points":[{"Position":1,"Points":10},{"Position":2,"Points":8},{"Position":3,"Points":6},{"Position":4,"Points":5},{"Position":5,"Points":4},{"Position":6,"Points":3},{"Position":7,"Points":2},{"Position":8,"Points":1}]}]}

これは、MVC モデル クラスにマップされる json シリアル化されたオブジェクトです。

モデルをパラメーターとして受け取るコントローラーアクションを構成して、フォーム「モデル」変数から特定のモデルクラスにjson文字列を自動的に逆シリアル化したいと思います

[HttpPost]
public ActionResult DoSomething(DomainModel model)
    {
    }

また、そのモデルのカスタム Model Binder を作成することは避けたいと思います。代わりに、同様のシナリオで機能する汎用的なものを用意します。

何か案は?

ありがとう、ステボ

4

1 に答える 1