title: How do I populate a dropdown list on an ascx view user control MVC?
body: <p>I have a drop-down list hardcoded in an MVC View User Control page and would like to populate this from a database table. The MVC View page Inherits data coming in from my controller.  This drop-down list would contain something like a list of states for the user to choose to set an item for my main object. This list would not fit into the data that is being passed into the View.</p>
  
  <p>Where and how would you get the data for the drop-down list into an MVC View user control?  Webform user controls have a code-behind page which could help to load this information from the database and pass to the HTML rendering side.  How would this be done with MVC using the correct separation of concerns approach?</p>
  
  <p>Controller</p>
  
  <pre><code>public ActionResult Inboxes() 
  { 
      var vm = new ListInboxesViewModel(); 
      vm.Inboxes = MyDataService.GetInboxes().OrderBy(i =&gt; i.InboxName); 
      return View(vm); 
  } 
  </code></pre>
  
  <p>Main View</p>
  
  <pre><code>&lt;% Html.RenderPartial("InboxesGrid", Model.Inboxes); %&gt;
  </code></pre>
  
  <p>Partial View</p>
  
  <pre><code>&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;IEnumerable&lt;MoniteredInbox&gt;&gt;" %&gt; 
  &lt;div&gt; 
     &lt;table&gt;
         &lt;tr&gt;&lt;td&gt;
             &lt;select id="SelectedStateddl"&gt;
                 &lt;!-- Selected states from database Table --&gt;
             &lt;/select&gt;
         &lt;/td&gt;&lt;/tr&gt;
     &lt;/table&gt; 
  &lt;/div&gt; 
  </code></pre>