title: Exception "There is no ViewData item of type 'IEnumerable<SelectListItem>" MVC
body: <p>Hello All I am new to MVC and I am unable to find the solution to the following exception.</p>
  
  <p><strong>"There is no ViewData item of type 'IEnumerable' that has the key 'Department'."</strong> </p>
  
  <p>Here is the cshtml code for it</p>
  
  <pre><code>@using LearningMVCDAL
  @using LearningMVCDAL.Classes
  @model Employee
  
  @{
      ViewBag.Title = "Create";
  }
  
  &lt;h2&gt;Create&lt;/h2&gt;
  
  @using (Html.BeginForm())
  {
      @Html.ValidationSummary(true)
  
      &lt;fieldset&gt;
          &lt;legend&gt;Employee&lt;/legend&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.Name)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.Name)
              @Html.ValidationMessageFor(model =&gt; model.Name)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.Gender)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.DropDownList("Gender", new List&lt;SelectListItem&gt;{ 
         new SelectListItem { Text="Male", Value="Male"},
         new SelectListItem { Text="Female", Value="Female"}},"Select Gender")
              @Html.ValidationMessageFor(model =&gt; model.Gender)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.City)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.City)
              @Html.ValidationMessageFor(model =&gt; model.City)
          &lt;/div&gt;
          &lt;div class="editor-label"&gt;
              @Html.Label("Department")
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.DropDownList("Department", (IEnumerable&lt;SelectListItem&gt;)ViewBag.Departments,"Select Department")
          &lt;/div&gt;
          &lt;p&gt;
              &lt;input type="submit" value="Create" /&gt;
          &lt;/p&gt;
      &lt;/fieldset&gt;
  }
  
  &lt;div&gt;
      @Html.ActionLink("Back to List", "Index")
  &lt;/div&gt;
  </code></pre>
  
  <p>Controller Code</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Mvc;
  using LearningMVCBLL;
  using LearningMVCDAL;
  using LearningMVCDAL.Classes;
  
  namespace LearningMVC.Controllers
  {
      public class EmployeeController : Controller
      {
  
          #region ObjectDeclartions
          EmployeeBusinessLayer objEmployeeBusinessLayer = new EmployeeBusinessLayer();
          DepartmentBusinessLayer objDepartmentBusinessLayer = new DepartmentBusinessLayer();
          #endregion
          public ActionResult Index()
          {
              List&lt;Employee&gt; employees = objEmployeeBusinessLayer.Employee;
              return View(employees);
          }
          [HttpGet]
          public ActionResult Create()
          {
              List&lt;Department&gt; departments = new List&lt;Department&gt;();
              departments = objDepartmentBusinessLayer.Department;
              SelectList departmentList = new SelectList(departments, "ID", "Name");
              ViewBag.Departments = departmentList;
              return View();
          }
          [HttpPost]
          public ActionResult Create(FormCollection formCollection)
          {
              if (ModelState.IsValid)
              {
                  foreach (string key in formCollection.AllKeys)
                  {
                      Response.Write("Key = " + key + "  ");
                      Response.Write("Value = " + formCollection[key]);
                      Response.Write("&lt;br/&gt;");
                  }
              }
              return View();
          }
      }
  }
  </code></pre>
  
  <p>I changed it but still got the same error. I am getting this error when I am posting the data "HttpPost" Create Function is called.
  Thanks in Advance.</p>