Asp.net mvc 将选择转换为MVC 5的下拉列表

Asp.net mvc 将选择转换为MVC 5的下拉列表,asp.net-mvc,razor,razor-declarative-helpers,Asp.net Mvc,Razor,Razor Declarative Helpers,我有这个选择,我需要把它转换成DropDownlistFor呼叫 有人能帮忙吗 <select class="form-control" name="QuestionBasicSection.Questions[@counter].ANSWER_LOOKUP_OPTION_ID" id="@selectId"> @foreach (var x in questionBasicSection.Questions[j].LookupGroup) { <

我有这个选择,我需要把它转换成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>

@foreach(questionBasicSection.Questions[j].LookupGroup中的变量x)
{
@x、 正文
}
这是一个框架,我只是不知道如何设置SelectList和Selected值

@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 
           )
@Html.DropDownListFor(q=>questionBasicSection.Questions[@counter]。回答\u查找\u选项\u ID,
新选择列表(
新列表{
新的{value=0,text=“Red”},
新的{value=1,text=“Blue”},
新建{value=2,text=“Green”}
},
“价值”,
“文本”,
//不确定如何设置所选的
)

DropDownListFor的工作原理是将源/目标属性作为第一个参数,将选项数组作为第二个参数。在您的示例中:

questionBasicSection.Questions[@counter]。回答\u查找\u选项\u ID

模型上的该属性应包含希望DropDownList设置为的初始值。例如,如果希望DropDownList在页面加载时显示“蓝色”,请在控制器中(或在创建模型的任何位置)将
ANSWER\u LOOKUP\u OPTION\u ID
的值设置为2