title: DropDownListFor from Entity Framework
body: <p>This probably has been asked over a thousand times already but I just can't get my head around this after trying it for over 10 times.</p>
  
  <p>I'm trying to create a 'Teacher' where one can select a Division the teacher is in.</p>
  
  <p>Model:</p>
  
  <pre><code>public class CreateTeacherModel
  {
      [Required]
      [Display(Name = "User name")]
      public string UserName { get; set; }
  
      [Required]
      [DataType(DataType.EmailAddress)]
      [Display(Name = "Email address")]
      public string Email { get; set; }
  
      [Required]
      [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
      [DataType(DataType.Password)]
      [Display(Name = "Password")]
      public string Password { get; set; }
  
      [DataType(DataType.Password)]
      [Display(Name = "Confirm password")]
      [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
      public string ConfirmPassword { get; set; }
  
      [Display(Name = "Division")]
      public Division Division { get; set; }
  
      [Display(Name = "Divisions")]
      public Dictionary&lt;Guid, Division&gt; Divisions
      {
          get
          {
              var db = new IBPVEntities();
  
              Division = db.Division.FirstOrDefault();
  
              return db.Division.ToDictionary(division =&gt; division.DivisionId);
          }
      }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>    [Authorize(Roles = "Administrator")]
      public ActionResult CreateTeacherTest()
      {
          return View(new CreateTeacherModel());
      }
  
      [Authorize(Roles = "Administrator")]
      [HttpPost]
      public ActionResult CreateTeacherTest(CreateTeacherModel model)
      {
          if (ModelState.IsValid)
          {
              var selectedDivision = model.Division;
              // Save to database.
          }
  
          return View(model);
      }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>@Html.DropDownListFor(x =&gt; x.Division, new SelectList(Model.Divisions, "DivisionId", "Name"))
  </code></pre>
  
  <p>Division has 2 properties: DivisionId (guid) and Name (string).</p>
  
  <p>I totally lost track on what to do now, can someone help me out on this?</p>
  
  <p>Thanks in advance!</p>