asp.net mvc SelectList使用
action代码:
BusinessPublicContent pc = db.BusinessPublicContent.Where(m => m.BusinessPublicContentID == id).FirstOrDefault(); ViewBag.data = pc; var query = from m in db.BusinessMenu where m.Status == 1 && m.IsDelete == 0 && m.ParentBusinessMenuID == 0 select new { BusinessMenuID = m.BusinessMenuID, BusinessMenuName = m.BusinessMenuName }; List<SelectListItem> items = new SelectList(query.ToList(), "BusinessMenuID", "BusinessMenuName",id).ToList(); ViewBag.items = items;
html代码:
@Html.DropDownList("mid", ViewBag.items as IEnumerable<SelectListItem>)