【发布时间】:2014-03-21 15:38:42
【问题描述】:
我正在尝试在我的表单上创建一个选择列表。我正在使用 Razors Html.DropDownListFor,但我不确定如何使用模型中的适当值正确填充 DropDownList。
for (int i = 0; i < Model.Questions.Count(); i++)
{
for (int j = 0; j < Model.Questions[i].Options.Count(); j++)
{
@Html.DropDownListFor(m=>m.Questions[i].Options[j].IsSelected, ????)
}
}
型号:
public class QuestionViewModel
{
public int? Id { get; set; }
public string QuestionType { get; set; }
public string SubType { get; set; }
public string Text { get; set; }
public int SortOrder { get; set; }
public bool IsHidden { get; set; }
public List<QuestionOptionViewModel> Options { get; set; }
}
public class QuestionOptionViewModel
{
public int? Id { get; set; }
public string Text { get; set; }
public string Value { get; set; }
public bool IsChecked { get; set; }
public int Selected { get; set; }
}
【问题讨论】:
标签: c# asp.net-mvc razor