I have a problem with a multiselectlist, if I hover dropObjectcategories in debug-mode it contains 4 items that should be selected.
List<int> selectedObjectcategoryIDs = new List<int>();
foreach (Objectcategory item in bo.Objectcategorie开发者_JS百科s)
{
selectedObjectcategoryIDs.Add(item.ObjectcategoryID);
}
MultiSelectList dropObjectcategories = new MultiSelectList(_bs.GetObjectcategories(), "ObjectcategoryID", "ObjectcategoryName", selectedObjectcategoryIDs);
still it gets rendered without any items selected like this:
<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>
what might be wrong here?
/M
Try something like:
var selectedObjectcategoryIDs =
from oc in bo.Objectcategories
select oc.ObjectcategoryID;
MultiSelectList dropObjectcategories = new MultiSelectList(_bs.GetObjectcategories(), "ObjectcategoryID", "ObjectcategoryName", selectedObjectcategoryIDs);
Does it work?
精彩评论