title: ASP.NET Binding linq query results to HTML.DropDownList() using MVC
body: <p>I am trying to build a drop down list with a single database call.</p>
  
  <p>My table consists of an Id column and a CompanyName column.  I need to display the CompanyName to the user and when one is selected set the Id for the page to Id.</p>
  
  <p>I have put a simple model together to store the information:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Data.Entity;
  using System.Linq;
  using System.Web;
  
  namespace Portal.Models
  {
      public class CompanyListId
      {
          public int Id { get; set; }
          public string CompanyName { get; set; }
      }
  
      public class CompanyListIdDBContext : DbContext
      {
          public DbSet&lt;CompanyListId&gt; Contacts { get; set; }
      }
  }
  </code></pre>
  
  <p>But I am having an issue with the controller and razor call in the view.</p>
  
  <p>My controller:</p>
  
  <pre><code>public void CompanyListIdSearch()
          {
              using (var dc = new CompanyListIdDBContext())
              {
                  var content = from p in db.Companies
                                  select new { p.CoId, p.CompanyName };
              }
          }
  </code></pre>
  
  <p>Razor call in View:</p>
  
  <pre><code>&lt;div id="partners" class="linen"&gt;
  
                          @{Html.DropDownList("CompanyListIdSearch", new SelectList(Model.CompanyName));}
                      &lt;/div&gt;
  </code></pre>
  
  <p>Grabbing the model at the top of a view <code>@model Portal.Models.CompanyListId</code></p>
  
  <p>So at a high level what I am trying to do is have a view that calls the controller with a razor tag, the controller updates the model with data and then that data is displayed in the drop down.  Am I approaching this the wrong way?</p>
  
  <p>I am getting this error:</p>
  
  <pre><code>The model item passed into the dictionary is of type 'Portal.Models.DashboardContents', but this dictionary requires a model item of type 'Portal.Models.CompanyListId'. 
  </code></pre>