I'm learning ASP.NET MVC. I had a small problem when dealing with dropdownlist.
This is what I did in controller
List<Int32> myList = new List<Int32>();
var a = (from m in datacontext.services
select m.ServiceID);
myList = a.ToList();
ViewData["ServiceID"] = new SelectList((IEnumerable<SelectListItem>)
a.ToList(), "ServiceID", "ServiceID");
In the view
@Html.DropDownListFor(model => model.ServiceID, ViewData["ServiceID"] as SelectList)
This results in an error
Unable to cast object of type 'System.Collections.Generic.List
1[System.Int32]' to type 'System.Collections.Generic.IEnumerable
1[System.Web.Mvc.SelectListItem]'."
How can this be resolved?
What's the best way to deal with populating dropdownlist with a query?