ASP.NET MVC4中使用Html.DropDownListFor的方法示例

  public ActionResult PageDetail()

  {

  var thisList = _sysDepartmentBll.GetAllDepartmentList();//数据源

  //添加一条默认数据

  var resultList = new List

  {

  new SelectListItem {Text = "--请选择--", Selected = true, Value = ""}

  };

  //将数据源添加到resultList集合中

  resultList.AddRange(thisList.Select(thisModel => new SelectListItem

  {

  Text = thisModel.DepartmentName,

  Selected = false,

  Value = thisModel.DepartmentId

  }));

  ViewBag.DepartmentList= GetDepartmentSelectList(_sysDepartmentBll.GetAllDepartmentList());

  return View();

  }