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=="人事部" });