title: MVC 3 DropdownList for Entity Object Property
body: <p>I have a Domain Entity for User and I'm trying to create a simple "update user page" in ASP.NET MVC 3. I am having trouble setting the user's Role using a @Html.DropDownListFor to <strong>select</strong> and <strong>commit</strong> the change to a role. </p>
  
  <p>I use in my view I use a lot of:</p>
  
  <pre><code>@Html.TextBoxFor(m =&gt; m.Username)
  @Html.TextBoxFor(m =&gt; m.Username)
  @Html.TextBoxFor(m =&gt; m.Username)
  </code></pre>
  
  <p>Here's my <strong>User Domain Entity</strong>. Notice how the Address and Roles are Foreign Key Properties to other classes. </p>
  
  <pre><code>public class User
  {
      public int UserId { get; set; }
      public string Username { get; set; }
      public string Password { get; set; }
      public string Email { get; set; }
      public string FirstName { get; set; }
      public string LastName { get; set; }
      public virtual Address CurrentAddress { get; set; }
      public virtual Role Role { get; set; }
  }
  </code></pre>
  
  <p><strong>This is my Role Entity</strong> </p>
  
  <pre><code>public class Role
  {
      public int RoleId{ get; set; }
      public string Type{ get; set; }
      public string Description{ get; set; }
      public virtual ICollection&lt;User&gt; Users { get; set; }
  }
  </code></pre>