私はそれを「標準的な」方法で行いました:
public ActionResult Respondent()
{
return View(Session["Respondent"]); //passing the model
}
[HttpPost]
public ActionResult Respondent(Respondent resp)
{
repository.UpdateRespondent(Respondent resp);
Session["Respondent"] = respondent; //put back into session
return View(respondent); //redraw view, passing in respondent
}
そして、それは機能します。MVC が FORM 値を自動的に収集するためにのみ、POST アクションで応答者モデルを渡しています。ビュー内には、すべてのプロパティに対してこれらがあります。
@using (Html.BeginForm())
{
@Html.LabelFor(model => model.FirstName)
@Html.EditorFor(model => model.FirstName)
@Html.ValidationMessageFor(model => model.FirstName)
// and so on...
}
私の質問は、(Session に存在する) Session オブジェクトを既に使用している場合、Session オブジェクトをビュー内のモデルとして使用して、HttpPost がすべての検証を含めて機能する方法はありますか? では、どのようにして値が収集され、セッションに戻されるのでしょうか?
ありがとうございました。