title: How do I select a value for a dropdownlist from a database in ASP.NET MVC and C#?
body: <p>I have a <code>dropdownlist</code> which is stored within <code>TitleEditorTemplate</code>:</p>
  
  <pre><code>&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;string&gt;" %&gt;
  &lt;%=Html.DropDownList("", 
                        new SelectList(
                            new[] { "MR", "MRS", "MISS", "MS", "SIR", "REV", "DR"}
                        )
  )%&gt;
  </code></pre>
  
  <h3>View</h3>
  
  <pre><code>&lt;%=Html.EditorFor(x =&gt; x.Title, "TitleEditorTemplate")%&gt;
  </code></pre>
  
  <h3>ViewModel</h3>
  
  <pre><code>[UIHint("TitleEditorTemplate")]
  [Required(ErrorMessage = "Please select a title")]
  public string Title { get; set; }
  </code></pre>
  
  <h3>Controller</h3>
  
  <pre><code>//Results of a query of textboxes
  Title = data.Title,
  </code></pre>
  
  <h3>Problem</h3>
  
  <p>My problem occurs when I'm trying to edit (pulling data from a database) the information and then write an <code>UPDATE</code> to the database, everything else is pulled back correctly and inserted into the correct textboxes.</p>
  
  <p>However the <code>dropdownlist</code> automatically selects the first option 'MR' rather than 'MRS'.</p>
  
  <p>I know it must have something to do with how it generates the <code>dropdownlist</code>but I don't know how to fix this. </p>
  
  <h3>DropDownList Code</h3>
  
  <pre><code>&lt;select id="Title_TitleDropDown" name="Title.TitleDropDown"&gt;&lt;option&gt;MR&lt;/option&gt;
  &lt;option&gt;MRS&lt;/option&gt;
  &lt;option&gt;MISS&lt;/option&gt;
  &lt;option&gt;MS&lt;/option&gt;
  &lt;option&gt;SIR&lt;/option&gt;
  &lt;option&gt;REV&lt;/option&gt;
  &lt;option&gt;DR&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>What am I missing? How do I get it to choose the option selected from the database as the default selection?</p>
  
  <p>For example:</p>
  
  <p>Database columns</p>
  
  <ul>
  <li>Title: DR </li>
  <li>Forename: John</li>
  <li>Surname: Smith</li>
  </ul>
  
  <p>When the user wants to update this information, they can do so. Within my aspx page it will popluate both the forename/surname textboxes however not the dropdownlist, this instead becomes the default value of "MR" so the name becomes Mr John Smith rather than Dr John Smith.</p>