我在模型中有问题和答案列表。在一些问题中有4个选项,有些问题有2个选项。 我从后端获得选项,我从模型类绑定到剃刀视图。 现在,如果答案值为null意味着单选按钮正在显示,但如果单选按钮选项值为空则我不想要单选按钮。
@for (int j = 0; j < Model.Count; j++)
{
i++;
<div class="panel-heading online-test" role="tab" id="">
<h5 class="panel-title">
@Html.HiddenFor(m => m[j].ID)
@Html.HiddenFor(m => m[j].SkillId)
@i) @Html.DisplayFor(m => m[j].QuestionText)
</h5>
</div>
foreach (var k in Model[j].Options)
{
<div class="panel-collapse">
<div class="panel-body online-test-options">
<div class="input-group">
<div class="col-lg-12" id="radiolist">
@Html.RadioButtonFor(m => m[j].SelectedAnswer, "A")
<label for="@k.AnswerId">@k.Option1</label>
</div>
<div class="col-lg-12">
@Html.RadioButtonFor(m => m[j].SelectedAnswer, "B")
<label for="@k.AnswerId">@k.Option2</label>
</div>
<div class="col-lg-12">
@Html.RadioButtonFor(m => m[j].SelectedAnswer, "C")
<label for="@k.AnswerId">@k.Option3</label>
</div>
<div class="col-lg-12">
@Html.RadioButtonFor(m => m[j].SelectedAnswer, "D")
<label for="@k.AnswerId">@k.Option4</label>
</div>
</div>
</div>
</div>
}
}
public class QuestionsModel
{
public decimal ID { set; get; }
public decimal SkillId { get; set; }
public string QuestionText { set; get; }
public List<Answer> Options { set; get; }
public string SelectedAnswer { set; get; }
public QuestionsModel()
{
Options = new List<Answer>();
}
}
public class Answer
{
public int AnswerId { get; set; }
public string Option1 { set; get; }
public string Option2 { set; get; }
public string Option3 { set; get; }
public string Option4 { set; get; }
}
public class Evaluation
{
public List<QuestionsModel> Questions { set; get; }
public Evaluation()
{
Questions = new List<QuestionsModel>();
}
}
请帮忙解决.. 在此先感谢。