我的DropDownListFor
下面的代码,并正在确定MVC3剃刀的SelectedValue在DropdownListFor
@Html.DropDownListFor(Function(model) model.Habilitacoes, New SelectList(ViewBag.Habilitacoes, "KeyHL", "DescricaoHL"), New With {.class = "FillHSpace"})
的ViewBag.Habilitacoes
是List(Of T)
但知道我要的SelectedValue
添加到DropDownListFor
,所以我使用了下面的代码,但不起作用。
@Html.DropDownListFor(Function(model) model.Habilitacoes, New SelectList(ViewBag.Habilitacoes, "KeyHL", "DescricaoHL", model.Habilitacoes), New With {.class = "FillHSpace"})
我该如何声明SelectedValue
?
我会在模型上使用属性(例如'SelectedHabilitaco' - 无论是什么;))。并将其用作'DropDownListFor'的第一个参数 - 就像在这个答案中一样:http://stackoverflow.com/questions/3386998/dropdownlistfor-display-a-simple-list-of-strings/3387210#3387210(参见更新2 )。 – Yakimych