title: Razor, MVC4, @html.dropdownlistfor problems
body: <p>I'm trying to create a drop down list that populates from a database. I have:</p>
  
  <pre><code>public class Employee
      {
          [Key]
          public int Id { get; set; }
          [Required]
          public String FirstName { get; set; }
          [Required]
          public String LastName { get; set; }
          [Required]
          public String JobTitle { get; set; }
      }
  
      public class Project
      {
          [Key]
          public int Id { get; set; }
          [Required]
          public String ProjectName { get; set; }
          [Required]
          public String CompanyName { get; set; }
      }
  
      public class ProjectHour
      {
          [Key]
          public int Id { get; set; }
          [Required]
          public decimal Hours { get; set; }
          [Required]
          public DateTime Date { get; set; }
          public virtual ICollection&lt;Employee&gt; employeeId { get; set; }
          public virtual ICollection&lt;Project&gt; projectId { get; set; }
      }
  </code></pre>
  
  <p>What I want is to create a form that will create new project hours associated with a project and an employee. I'm trying to use dropdownlists to display the employees and the projects on the create form. Obviously, I'm completely new at this, but what I have so far is:</p>
  
  <pre><code>[HttpPost]
       public ActionResult CreateProjectHour(ProjectHour newProjectHour)
       {
               using (var db = new TimesheetContext())
               {
                   IEnumerable&lt;SelectListItem&gt; emp = db.Employees
                    .Select(c =&gt; new SelectListItem
                    {
                        Value = c.Id.ToString(),
                        Text = c.LastName
                    });
                   ViewBag.EmployeeId = emp;
  
                   db.ProjectHours.Add(newProjectHour);
                   db.SaveChanges();
               }
  
               return RedirectToAction("ProjectHourList");
           }
       }
  </code></pre>
  
  <p>And on the form:</p>
  
  <pre><code>@model TimesheetMVC.Models.ProjectHour
  ...
  @Html.DropDownListFor(model =&gt; model.employeeId, (SelectList)ViewBag.EmployeeId)
  </code></pre>
  
  <p>Which is apparently horribly wrong. Any help would be much appreciated...!</p>