MVC3 で調査アプリを作成しています。私はこのクラスを持っています(簡略化):
public class Survey
{
public Respondent Respondent { get; set; }
}
そして私の見解では:
@model Survey
// bla bla bla
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
@Html.Partial("_Respondent", Model.Respondent)
}
私がそれを投稿すると、survey.Respondent = null :(
[HttpPost]
public ActionResult Survey(Survey survey)
{
return RedirectToAction("Index");
}
_Respondednt 部分ビューの簡略化されたコード:
@model Mercer.FITT.Respondent
<fieldset>
<legend>Respondent Information</legend>
<table>
<tr>
<td>
@Html.LabelFor(model => model.Name)
</td>
<td>
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</td>
</tr>
<tr>
<td>
@Html.LabelFor(model => model.JobTitle)
</td>
<td>
@Html.EditorFor(model => model.JobTitle)
@Html.ValidationMessageFor(model => model.JobTitle)
</td>
</tr>
</table>
</fieldset>
部分ビューを削除して、部分ビューのコンテンツをメイン ビューにコピーするだけで問題ありません。部分ビューからデータが収集されない理由はありますか? たぶん、部分ビューを別の方法で呼び出す必要がありますか?
どうもありがとう。