ASP.NET MVC – List To IEnumerable<SelectListItem> for DropDownList Item

ASP.NET MVC – List To IEnumerable<SelectListItem> for DropDownList Item

   Controller
 
   ViewBag.Nation = this.GetNation().Select( x => new SelectListItem { Text = x.NATION_NAME, Value = x.NATION_ID.ToString() });
   ViewBag.Team = this.GetTeam().Select( x => new SelectListItem { Text = x.TEAM_NAME, Value = x.TEAM_ID.ToString() });
 
   public List<NATION> GetNation()
   {
      … …
   }
 
   public List<TEAM> GetTeam()
   {
      … …
   }
   View
 
   @Html.DropDownList("Nation", ViewBag.Nation as IEnumerable<SelectListItem>, new { style = "… …" })
 
   …
 
   @Html.DropDownList("Team", ViewBag.Team as IEnumerable<SelectListItem>, new { style = "… …" })