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=="人事部" });
上一篇:termios结构体各成员的值(FreeBSD 12.0)


下一篇:nodejs简易实现一下bigpipe