我正在做在线考试我想保留学生在 http get 上的答案我只想选中 http get 上的复选框,我在我的查询中有它们我只想将它们添加到我的模型中
我的模特
public class Question
{
public int QuestionId { get; set; }
public string QuestionName { get; set; }
public int QuestionTypeId { get; set; }
public List<QuestionOption> Options { get; set; }
public int SelectedOption { get; set; }
public List<QuestionOption> SelectedOptioncheckBox { get; set; }
public int TestId { get; set; }
}
public class QuestionOption
{
public int OptionId { get; set; }
public string OptionName { get; set; }
public bool IsChecked { get; set; }
}
我的控制器
Question Q = new Question();
Q.SelectedOptioncheckBox = new List<QuestionOption>();
List<int> ChkOptions = studBal.GetCheckedAnswers((int)TestId, model[count].QuestionId, (int)(studBal.getStudentId(Session["sname"].ToString())));
for (int i = 0; i < ChkOptions.Count(); i++)
{
Q.SelectedOptioncheckBox.Add(ChkOptions.ElementAt(i))
}
我的查询
var data = (from temp in context.Student_Answer_Master
where temp.Test_Id == TestId && temp.Question_Id == QuestionId && temp.StudentId == StudentId
orderby temp.Option_Id ascending
select (int)temp.Option_Id).ToList();
return data;
我的观点
<div>
@if(chk==null || chk.Count()==0)
{
@Html.CheckBoxFor(m => Model[i].Options[j].IsChecked, new { id = "selectedOption" + (j + 1) })
@Html.HiddenFor(m => Model[i].Options[j].OptionId)
}
else if (chk [0]== Model[i].Options[j].OptionId)
{
@Html.CheckBoxFor(m => Model[i].SelectedOptioncheckBox[j].IsChecked, new { id = "selectedOption" + (j + 1) })
@Html.HiddenFor(m => Model[i].Options[j].OptionId)
}
<span>@Model[i].Options[j].OptionName</span>
</div>
正如您所看到的查询它在数据库中的列表ChkOptions中为我提供了选中的选项我只想在我的模型字段中 添加那个ChkOptions SelectedOptioncheckBox以便我可以显示已经在我的视图中选中的复选框