title: Automapper Mapping IEnumerable<SelectListItem> for Dropdown Menu
body: <p><strong>Problem</strong></p>
  
  <p>I am currently adding automapping to my MVC project and I am stuck. Right now I have a User model used to represent data in the database. I have to map that model to a EditUserModel which will be used when the Edit method is called. The EditUserModel has <code>IEnumerable&lt;SelectListItem&gt;</code> (for a dropdown menu) that I can't seem to figure out how to map.</p>
  
  <p><strong>Attempted Solution</strong></p>
  
  <p>As of right now I haven't tried to implement anything. I am unsure where the best place for the <code>IEnumerable&lt;SelectListItem&gt;</code> or where to populate it. Right now it is being populated in the Controller.</p>
  
  <p><strong>User.cs</strong></p>
  
  <pre><code>public class User
  {
      [Key]
      public int UserID { get; set; }
  
      public string Username { get; set; }
  
      public string Password { get; set; }
  
      public int RoleID { get; set; }
  
      [ForeignKey("RoleID")]
      public virtual Role Role { get; set; }
  }
  </code></pre>
  
  <p><strong>EditUserModel.cs</strong></p>
  
  <pre><code>public class EditUserViewModel
  {
      [HiddenInput(DisplayValue = false)]
      public int UserID { get; set; }
  
      [Required]
      public String Username { get; set; }
  
      [Required]
      [DataType(DataType.Password)]
      public string Password { get; set; }
  
      [DisplayName("Role")]
      [Required]
      public int RoleID { get; set; }
  
      //The trouble field
      public IEnumerable&lt;SelectListItem&gt; Roles { get; set; }
  }
  </code></pre>
  
  <p><strong>Controller.cs</strong></p>
  
  <pre><code>EditUserViewModel model = new EditUserViewModel();
  //Population of the dropdown menu
  model.Roles = context.Roles
      .ToList()
      .Select(x =&gt; new SelectListItem
      {
          Text = x.Description,
          Value = x.RoleID.ToString()
      });
  //Mapping that the automaper will take care of
  model.UserID = user.UserID;
  model.Username = user.Username;
  model.RoleID = user.RoleID;
  </code></pre>