title: MVC 4 DropDownListFor Set Selected Item Based on Text
body: <p>Normally when I use the DropDownListFor helper I'm selecting which item is selected based on an ID (int), but now I have a situation where I need to display which item is selected based on the text (string) and not an ID. In the controller the model is being set correctly to the value that I want with this property:</p>
  
  <pre><code>model.Title
  </code></pre>
  
  <p>An example title would be "Front Office". I have the following code in my Controller:</p>
  
  <pre><code>ViewBag.Titles = new SelectList(jobTitles, "Name", "Name");
  </code></pre>
  
  <p>and on the view I have this: </p>
  
  <pre><code>@Html.DropDownListFor(model =&gt; model.Title, ViewBag.Titles as SelectList)
  </code></pre>
  
  <p>The DropDownList is populating correctly with all the expected job titles, it just isn't selecting the correct job title based on <b>model.Title</b>.  What am I doing wrong?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>There seems to be something else potentially going wrong in my code, so I'm putting all of it here to see if I'm doing something wrong. </p>
  
  <p>Controller: </p>
  
  <pre><code>public ActionResult Edit(int id = 0)
      {
          StaffMember staffmember = StaffMember.SelectByID(id); // gets staff member from db
  
          ViewBag.Titles = new SelectList(JobTitle.SelectAll(), "Name", "Name", staffmember.Title); // JobTitle.SelectAll() returns List&lt;JobTitle&gt;
  
          StaffEditModel model = new StaffEditModel();
          model.ID = staffmember.ID;
          model.ClientID = staffmember.ClientID;
          model.FirstName = staffmember.FirstName;
          model.MiddleInitial = staffmember.MiddleInitial;
          model.LastName = staffmember.LastName;
          model.Title = staffmember.Title;
          model.Phone = staffmember.Phone;
          model.Email = staffmember.Email;
          model.Birthday = staffmember.Birthday;
          model.HireDate = staffmember.HireDate;
          model.Biography = staffmember.Biography;
  
          if (staffmember == null)
          {
              return HttpNotFound();
          }
          return View(model);
      }
  </code></pre>
  
  <p>Model:</p>
  
  <pre><code>public class StaffEditModel
  {
      public int ID { get; set; }
  
      public int ClientID { get; set; }
  
      [Required]
      [Display(Name = "First Name")]
      public string FirstName { get; set; }
  
      [Display(Name = "Middle Initial")]
      public string MiddleInitial { get; set; }
  
      [Required]
      [Display(Name = "Last Name")]
      public string LastName { get; set; }
  
      public string Title { get; set; } // this is the property I'm trying to show in DropDown
  
      [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
      public string Birthday { get; set; }
  
      [Display(Name = "Hire Date")]
      [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
      public string HireDate { get; set; }
  
      public string Email { get; set; }
  
      [MaxLength(14)]
      public string Phone { get; set; }
      public string Biography { get; set; }
  }
  </code></pre>
  
  <p>View: </p>
  
  <pre><code>@Html.DropDownListFor(model =&gt; model.Title, new SelectList(ViewBag.Titles,"Value","Text", Model.Title))
  </code></pre>