我的代码如下所示:
@for (var i = 0; i < Model.Count; i++)
{
<h2>Question @Html.DisplayFor(x => x[i].OrderIndex) </h2>
@Html.HiddenFor(x => x[i].SurveyId)
@Html.HiddenFor(x => x[i].QuestionId)
@Html.HiddenFor(x => x[i].AnswerId)
<br />
@Html.DisplayFor(x => x[i].QuestionText)
<br />
@Html.DisplayFor(x => x[i].QuestionText)
@if (Model[i].Type == QuestionType.Single)
{
<h2>Answer</h2>
@for (var ao = 0; ao < Model[i].Answer.AnswerOptions.Count; ao++)
{
@Html.RadioButtonFor(x => x[i].Answer.AnswerOptions[ao].IsSelectedAnswer, true) @Html.Raw(" ");
@Html.LabelFor(x => x[i].Answer.AnswerOptions[ao].IsSelectedAnswer, Model[i].Answer.AnswerOptions[ao].OptionText)<br />
@Model[i].Answer.AnswerOptions[ao].OptionText
}
}
}
我可以让所有其他控件类型正常工作,但我不知道如何将单选按钮连接到我的模型。它是嵌套的for循环。
我也试过了:
@Html.RadioButtonFor(x => x[i].Answer.AnswerOptions[ao].IsSelectedAnswer, Model[i].Answer.AnswerOptions[ao].OptionText)
@Html.Raw(" ");
这应该得到价值,但事实并非如此。此外,我无法获得displayfor或labelfor working:
@Html.LabelFor(x => x[i].Answer.AnswerOptions[ao].IsSelectedAnswer, Model[i].Answer.AnswerOptions[ao].OptionText)
<br />