title: Drop down list binding from another model in MVC
body: <p>I am new to asp.net mvc</p>
  
  <p>I have two tables tblEmployee and tblDepartment in both the tables common field is department id.
  If the user creating new employee they have to select their department list from tblDepartment table.I am getting list of departments from that table there is no issue in that,but when i submitting the form departmentid is going null into the DB.</p>
  
  <p>Models</p>
  
  <pre><code>public partial class Department
  {
      public Department()
      {
          this.tblEmployees = new HashSet&lt;Employee&gt;();
      }
      public int Id { get; set; }
      public string Name { get; set; }
      public virtual ICollection&lt;Employee&gt; tblEmployees { get; set; }
      public Employee employee { get; set; }
  }
  
  public partial class Employee
  {
      public int EmployeeId { get; set; }
      public string Name { get; set; }
      public string Gender { get; set; }
      public string City { get; set; }
      public Nullable&lt;int&gt; DepartmentId { get; set; }
  
      public virtual Department tblDepartment { get; set; }
      public List&lt;Department&gt; deprtment { get; set; }
      public virtual string Department { get; set; }
      public bool available { get; set; }
  }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>public ActionResult Create()
  {
      SampleDbContext Db = new SampleDbContext();
      List&lt;Employee&gt; employees = Db.Employees.Include("tblDepartment").ToList();
      ViewBag.list = new SelectList(Db.Departments, "Id", "Name");
  
      return View();
  }
  
  [HttpPost]
  public ActionResult Create( Employee employee)
  {
      SampleDbContext Db = new SampleDbContext();
      if (ModelState.IsValid)
      {
          Db.Employees.Add(employee);
          Db.SaveChanges();
          return RedirectToAction("Index");
      }
      return View(employee);
  }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>@model EmployeeList.Models.Employee
  ....  
  @using (Html.BeginForm()) 
  {
      @Html.AntiForgeryToken()
      &lt;div class="form-horizontal"&gt;
          &lt;h4&gt;Employee&lt;/h4&gt;
          &lt;hr /&gt;
          @Html.ValidationSummary(true, "", new { @class = "text-danger" })
          &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
              &lt;div class="col-md-10"&gt;
                  @Html.EditorFor(model =&gt; model.Name, new { htmlAttributes = new { @class = "form-control" } })
                  @Html.ValidationMessageFor(model =&gt; model.Name, "", new { @class = "text-danger" })
              &lt;/div&gt;
          &lt;/div&gt;
          .... // controls for other properties of Employee
          &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model.DepartmentId, "DepartmentId", htmlAttributes: new { @class = "control-label col-md-2" })
              &lt;div class="col-md-10"&gt;
                  @Html.DropDownList("list","select Depar")
                  @Html.ValidationMessageFor(model =&gt; model.DepartmentId, "", new { @class = "text-danger" })
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
              &lt;div class="col-md-offset-2 col-md-10"&gt;
                  &lt;input type="submit" value="Create" class="btn btn-default" /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  }
  </code></pre>