title: MVC 5 Select List Item with current selection showing
body: <p>My apologies I will not try technical terms to explain my problem, I will try basic English - I want to have my select list to appear in my view with he current selected dealer chosen already (more details below). Thank you in Advance.</p>
  
  <p>I have a product which is stored in its own data table, which is sold by dealers and against the product I store the dealer number who sold it.</p>
  
  <p>I get the dealer number from the dealer data table.</p>
  
  <p>On the web page I create a drop down list when the product is sold which the user selects the dealer name who sold it. I have managed to create the list which shows the names but when selected stores the ID in the product table of the dealer this is working fine.</p>
  
  <p>I am just struggling when I come to edit the product have the select list appear and show the current selected dealer, it always appears with first dealer in the list. I have searched but due to my getting this code fudged together from other SO posts, I can not find a post which works with my code example.</p>
  
  <p>Any feedback/help/suggestions would be greatly appreciated.</p>
  
  <p>Controller</p>
  
  <pre><code>            // Create drop down list of dealer names to allow users to select from easily identifiable list rather than find number first before coming to the page.
          var list = db.Dealers.OrderBy(r =&gt; r.Name).ToList().Select(rr =&gt;
          new SelectListItem { Value = rr.Name.ToString(), Text = rr.Name }).ToList(); // Require to code and set value based on current selected name.
  
          ViewBag.DealerName = list;
  </code></pre>
  
  <p>Razor view Code:</p>
  
  <pre><code>            &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model.Dealer_ID, htmlAttributes: new { @class = "control-label col-md-4" })
              &lt;div class="col-md-8"&gt;
                  @*
                  @* Custom display for drop down list which shows Dealer Name instead of numeric ID Value *@
                  @Html.DropDownListFor(m =&gt; m.Dealer_ID, (IEnumerable&lt;SelectListItem&gt;)ViewBag.DealerName, new { htmlAttributes = new { @class = "form-control" } })
              &lt;/div&gt;
          &lt;/div&gt;
  </code></pre>