大水牛

 

mvc DropDownList默认选项

  DDDContext db = new DDDContext();
            List<SelectListItem> selectlistDistrict = new List<SelectListItem>();
            foreach (var s in db.Department)
            {
                if (s.Name=="人事部")
                {
                    selectlistDistrict.Add(new SelectListItem()
                    {
                        Text = s.Id.ToString(),
                        Value = s.Name,
                        Selected = true
                    });
                }
                else
                {
                    selectlistDistrict.Add(new SelectListItem()
                    {
                        Text = s.Id.ToString(),
                        Value = s.Name,
                     
                    });
                }
            }
            ViewBag.select = selectlistDistrict;

 

ViewBag.select =db.Department.select(c=>new SelectListItem(){
Value=c.ID,
Text=c.Name,
Selected=c.Name=="人事部"

});

 

posted on 2016-06-09 21:32  liucyi  阅读(286)  评论(0编辑  收藏  举报

导航