我有这个视图用于呈现表单
@using ExpertApplication.ViewModels
@model IEnumerable<QuestionViewModel>
@{
ViewBag.Title = "GetQuestions";
}
@using(Html.BeginForm("ProcessAnswers", "Home", FormMethod.Post))
{
foreach(QuestionViewModel questionViewModel in Model)
{
Html.RenderPartial("QuestionPartialView", questionViewModel);
}
<input type="submit" value="Send data"/>
}
}
<h2>GetQuestions</h2>
和局部视图
@using ExpertApplication.ViewModels
@model QuestionViewModel
<div id="question">
@Model.Text
<br />
<div id="answer">
@foreach(var answer in Model.AnswerViewModels)
{
@(Model.IsMultiSelected
? Html.CheckBoxFor(a => answer.Checked)
: Html.RadioButtonFor(a => answer.Checked, false))
@Html.LabelFor(a => answer.Text)
<br />
}
</div>
</div>
我想从 From 获取数据
[HttpPost]
public ActionResult ProcessAnswers(IEnumerable<QuestionViewModel> answerForQuesiton)
{
//answerForQuestion always is null
}
但参数 answerForQuesiton 为空。如何解决这个问题?