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>)

 

posted @ 2015-11-25 18:19  大空白纸  阅读(2673)  评论(0编辑  收藏  举报