title: LINQ distinct to @Html.DropDownList
body: <p>Ok I am having a lot of trouble for something I think should be pretty easy.  I am trying to populate a dropdown list with distinct values from a table.</p>
  
  <p>This linq provides the list of departments I need for each drop down option.</p>
  
  <pre><code>IPACS_Master_Lists
     .Where (x =&gt; (x.Department != null))
     .Select (s =&gt; s.Department)
     .Distinct ()
     .Select (v =&gt; v)
  </code></pre>
  
  <p>How do I make a dropdown list with this?</p>
  
  <p>I've tried messing with @Html.DropDownList but cannot get anything to work it seems.</p>
  
  <p>My controller is as follows.  I tried to pass it in with ViewBag but couldn't get that to work either.</p>
  
  <pre><code>public ActionResult Index()
          {
              var docs = db.IPACS_Master_List;
              ViewBag.Departments = new SelectList(db.IPACS_Master_List.Where(x =&gt; (x.department != null)).Select (s =&gt; s.department).Distinct().Select (v =&gt; v), "id", "department", 0);
              return View(docs);
          }
  </code></pre>