我有这个选择,我需要将它转换为 DropDownlistFor 调用。
任何人都可以帮忙:
<select class="form-control" name="QuestionBasicSection.Questions[@counter].ANSWER_LOOKUP_OPTION_ID" id="@selectId">
@foreach (var x in questionBasicSection.Questions[j].LookupGroup)
{
<option value="@x.Value" selected="@x.Selected">@x.Text</option>
}
</select>
这是一个骨架,我只是不确定如何设置 SelectList 和 Selected Value
@Html.DropDownListFor(q => questionBasicSection.Questions[@counter].ANSWER_LOOKUP_OPTION_ID,
new SelectList(
new List<Object>{
new { value = 0 , text = "Red" },
new { value = 1 , text = "Blue" },
new { value = 2 , text = "Green"}
},
"value",
"text",
// Not sure how to set selected
)