我正在尝试创建一个带有下拉菜单的可编辑列表。
SelectList不会选择Device_Parts中给定的值。它给出了价目表的第一个价值。
控制器:
var Device_Parts = (from dp in db.Device_Parts
join dc in db.DeviceConfig on dp.Device_config_id equals dc.Device_config_id
where dp.Device_config_id == Id
select dp).ToList();
var SelectedCMI = (from Item in db.pricelist
select new { Id = Item.Price_id, name = Item.bas_art_nr });
ViewData["SelectedCMI"] = new SelectList(SelectedCMI, "Id", "name");
部分视图:
@Html.DropDownListFor(a => a[j].Price_id, (IEnumerable<SelectListItem>)ViewData["SelectedCMI"], new { onchange = "Action(this.value);", @class = "form-control", @id = "code" })
我在做什么错了?