我有一个列表,SelectedListItem
我将它从控制器发送到使用 ViewBag 进行查看。List中有一个具有selected = true
属性的 SelectedListItem。
鉴于代码是:
@Html.DropDownListFor(model => model.Configuration,
new SelectList(ViewBag.ListOfConfigValues,"Value", "Text"),
new { @class = "ddl", @id = "ddlForConfiguration"})
我还在model.Configuration
.
我知道我们可以将选定的索引与Value
,一起传递Text
。
在控制器中我设置ViewBag
为
ViewBag.ListOfConfigValues = defaultObj.configurationsList;
return PartialView(detail);
configurationList
如下
{Text = "Red", Value = "Color1", Selected = false},
{Text = "Blue", Value = "Color2", Selected = true},
{Text = "Green", Value = "Color3", Selected = false}