我有一堂具有以下属性的课程。它构建了一个SelectList
现有列表中的对象,然后设置所选项目。
public SelectList ProviderTypeList
{
get
{
SelectList list = new SelectList([...my collection...], "Value", "Key");
SelectListItem item = list.FirstOrDefault(sli => sli.Text == SelectedProviderType);
if (item != null)
item.Selected = true;
return list;
}
}
然而,当这段代码完成后,item.Selected
是真的。但相应的项目SelectList
集合仍然为空。
我似乎找不到更新集合中对象的方法,以便在生成的 HTML 中使用该设置。
我在用着@Html.DropDownListFor
来渲染 HTML。但我可以看到,该代码执行后,集合中的对象并未被修改。
谁能看到我缺少什么吗?
有一个可选的附加参数SelectList
SelectList list = new SelectList([...my collection...], "Value", "Key", SelectedID);
检查定义
public SelectList(IEnumerable items, string dataValueField, string dataTextField,
object selectedValue);
它设置选定的值并且与dataValueField
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)