title: Setting the value of a database-driven DropDownListFor in MVC
body: <p>There's a number of questions about this on SO already and I've looked through quite a few of them, but am still unable to figure out exactly what I'm doing wrong here. I'm able to have a dropdownlistfor populate the select values without any issue, but setting the value of the list from the database isn't working.</p>
  
  <p>Basically the same select list is used multiple times on the page, and there is a seperate model variable that tracks the value for each instance. Here's an example of for the hdr_base_uom variable:</p>
  
  <p>The model:</p>
  
  <pre><code>public string hdr_base_uom { get; set; }
  public List&lt;UomOption&gt; putupOptions { get; set; }
  
  public class UomOption
  {
      public int uom_id { get; set; }
      public string uom_description { get; set; }
  }
  </code></pre>
  
  <p>Populating the list:</p>
  
  <pre><code>public List&lt;UomOption&gt; GetPutupOptions()
  {
      try
      {
          using (IfxConnection con = new IfxConnection(WebConfigurationManager.AppSettings["IBMCONN"].ToString()))
              {
                  con.Open();
                  List&lt;UomOption&gt; uomOptions= con.Query&lt;UomOption&gt;("select uom_id, initcap(uom_description) as uom_description " +
                      " from oe_unitom " +
                      " where uom_group = 1 order by uom_description").ToList();
                  con.Close();
                  uomOptions.Insert(0, new UomOption(){ uom_id = 0, uom_description = " "});
                  return uomOptions;
              }
          }
          catch (Exception x)
          {
              throw x;
          }
      }
  </code></pre>
  
  <p>The view:</p>
  
  <pre><code>@Html.DropDownListFor(model =&gt; model.hdr_base_uom, new SelectList(Model.putupOptions, 
      "uom_id", "uom_description", Model.hdr_base_uom), 
      new { disabled = "disabled", style = "width:13em" })
  </code></pre>
  
  <p>If I simply display the value of <code>model.hdr_base_uom</code> on the page then the <code>uom_id</code> that is set to that variable shows up. Attempting to use that ID to set the value of the <code>dropdownlistfor</code> does nothing, however. For example if the <code>uom_id</code> is <code>58</code> which has the corresponding description of <code>"Roll"</code> to be displayed, instead of defaulting to Roll the <code>dropdownlistfor</code> instead shows the first element in the list (the empty element added above.)</p>
  
  <p>Any thoughts on what I'm doing wrong here?</p>