我有一个多选列表的问题,如果我在调试模式下悬停dropObjectcategories它包含4个应该选择的项目。
List<int> selectedObjectcategoryIDs = new List<int>();
foreach (Objectcategory item in bo.Objectcategories)
{
selectedObjectcategoryIDs.Add(item.ObjectcategoryID);
}
MultiSelectList dropObjectcategories = new MultiSelectList(_bs.GetObjectcategories(), "ObjectcategoryID", "ObjectcategoryName", selectedObjectcategoryIDs);
仍然会在没有选择任何项目的情况下进行渲染:
<select id="dropObjectcategories" multiple="multiple" name="dropObjectcategories"><option value="3">Airplanes</option><option value="10">Cars</option><option value="8">Computers</option><option value="9">Thingies</option></select>
这里可能有什么问题?
/ M
答案 0 :(得分:1)
尝试类似:
var selectedObjectcategoryIDs =
from oc in bo.Objectcategories
select oc.ObjectcategoryID;
MultiSelectList dropObjectcategories = new MultiSelectList(_bs.GetObjectcategories(), "ObjectcategoryID", "ObjectcategoryName", selectedObjectcategoryIDs);
有效吗?