モデル
@model List<Survey.SurveyQuestion>
SurveyQuestionには2つのプロパティがQuestionId
あり、QuestionText
Html.DropDownList("Questions", new SelectList(@Model))
@Html.DropDownList("Questions", new SelectList(@Model), "QuestionId", "QuestionText")
上記のコードからの出力:
DropDownListForは、フィールドQuestionIdを認識しない(または実際にはフィールドを認識しない)ため、使用できません。
@Html.DropDownListFor(item => item.QuestionId, new SelectList(Model,
"QuestionId", "QuestionText"), "--Select --"))
次のコードは、すべてのデータを正しく表示します。
@foreach (var item in Model)
{
<p>@item.QuestionId - @item.QuestionText</p>
}