title: VB.Net, MVC3, Razor, EF 4.1 DB First, and Linq - Populating DDL Options and Values
body: <p><strong>Background</strong> - I'm trying to populate a drop down list with state information from a database. I'd like the full state name to be the option and the state abbreviation to be the value. Example:</p>
  
  <pre><code>&lt;option value="AL"&gt;ALABAMA&lt;/option&gt;
  </code></pre>
  
  <p><strong>Current Progress</strong> - The full state names and abbreviations already exist in the DB. I've successfully populated the DDL with full state names from the DB. Here's the code I've used to do this (minus stuff I've deemed irrelevant).</p>
  
  <p>Model Context (generated from template):</p>
  
  <pre><code>Partial Public Class BrokerCRMEntities
      Public Property States() As DbSet(Of State)
  End Class
  </code></pre>
  
  <p>State Model (generated from template):</p>
  
  <pre><code>Partial Public Class State
      Public Property StateAbbrev As String
      Public Property StateFull As String
  End Class
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>Dim db As BrokerCRMEntities = New BrokerCRMEntities
  Dim StateList = New List(Of String)()
  Dim StateQuery = From d In db.States
                   Order By d.StateFull
                   Select d.StateFull
  StateList.AddRange(StateQuery)
  ViewBag.State = New SelectList(StateList)
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>@ModelType IEnumerable(Of BrokerCRM.BrokerCRMEntities)
  @Html.DropDownList("State", "")
  </code></pre>
  
  <p>This code produces a DDL which contains full state names. Example:</p>
  
  <pre><code>&lt;option&gt;ALABAMA&lt;/option&gt;
  </code></pre>
  
  <p><strong>Question</strong> - In addition to populating full state names like I've done above, I'd also like to populate the value of the select options in the same DDL with the state abbreviations in my DB/model. How is this done?</p>
  
  <p>Thanks!</p>