私はオンライン試験に取り組んでいます 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<int> 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; }
}
私のコントローラー
List<int> ChkOptions = studBal.GetCheckedAnswers((int)TestId, model[count].QuestionId, (int)(studBal.getStudentId(Session["sname"].ToString())));
//model[0].SelectedOptioncheckBox[i]
for (int i = 0; i < ChkOptions.Count(); i++)
{
model[count].SelectedOptioncheckBox[i]=ChkOptions.ElementAt(i);
}
私の見解
@for (int j = 0; j < Model[i].Options.Count(); j++)
{
<div>
@if (chk == null || chk.Count() == 0 )
{
@Html.HiddenFor(m=>Model[i].Options[j].OptionId)
@Html.CheckBoxFor(m => Model[i].Options[j].IsChecked)
}
else if ((chk[chkCount] == Model[i].Options[j].OptionId))
{
@Html.HiddenFor(m=>Model[i].Options[j].OptionId)
@Html.CheckBoxFor(m => Model[i].SelectedOptioncheckBox[j], new { @checked=true})
}
}
コントローラー側でわかるように、モデルで既に選択されているオプションを取得して、それらをビューに渡し、それに応じてチェックボックスを生成したいのですが、体がこれを解決できる場合は助けてください