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