title: How to get Selected Value in DropDownList from Database
body: <p>I want to get selected value in dropdownlist. </p>
  
  <p>My View:</p>
  
  <pre><code>&lt;div class="form-group"&gt;
      @Html.LabelFor(model =&gt; model.AccountRefNo, "Account Desc", new { @class = "control-label col-md-2" })
      &lt;div class="col-md-10"&gt;
          @Html.DropDownList("AccountRefNo", ViewBag.AccountRefNo as SelectList, "Account Desc", new { @class = "form-control" })
          @Html.ValidationMessageFor(model =&gt; model.AccountRefNo)
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="form-group"&gt;
      @Html.LabelFor(model =&gt; model.PartyID, "Party Type", new { @class = "control-label col-md-2" })
      &lt;div class="col-md-10"&gt;
          @Html.DropDownList("TypeID", ViewBag.TypeID as SelectList, "Party Type", new { @class = "form-control" })
          @Html.ValidationMessageFor(model =&gt; model.TypeID)
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>And, my Controller:</p>
  
  <pre><code>ViewBag.TypeID = new SelectList(db.PartyTypes, "TypeID", "TypeDesc", party.TypeID);
  
  string[] codes = { "2.20.40.10", "3.50.10.20" };
  ViewBag.AccountRefNo = new SelectList(db.ChartOfAccounts.Where(a =&gt; codes.Contains (a.AccountCode)), "AccountCode", "AccountDesc", party.AccountRefNo);
  return View(party);
  </code></pre>
  
  <p>It seems it is OK but I don't know where the problem is. Both dropdownlists filling the lists but both are selecting their OptionLabel i.e selecting "Party Type" and "Account Desc" respectively. </p>
  
  <p>Please help. Thanks!</p>