title: There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'Userlist'
body: <p>My User Model</p>
  
  <pre><code>    [Key]
      public int UserId { get; set; }
      [Required]
      [DisplayName("First Name")]
      public string FirstName { get; set; }
      [Required]
      [DisplayName("Last Name")]
      public string LastName { get; set; }
  
      public virtual List&lt;DptCRP&gt; DptCRPs { get; set; }
  </code></pre>
  
  <p>My Patient Model</p>
  
  <pre><code>        [Key]
          [Required]
          [DisplayName("Registration No")]
          public string PatientRegNo { get; set; }
          [Required]
          [DisplayName("Patient Name")]
          public string PatientName { get; set; }
          [Required]
          [DisplayName("Father Name")]
          public string FatherName { get; set; }
          public string ReferDpt { get; set; }
  
          public virtual List&lt;DptCRP&gt; DptCRPs { get; set; }
  </code></pre>
  
  <p>My DptCRP Model(UserId nad PatientRegNo is used as Foreign key in this model)</p>
  
  <pre><code>    [Key]
      public int CRPId { get; set; }
  
      [DisplayName("Provisional Diagnosis")]
      public string ProvisionalDiagnosis { get; set; }
      [DisplayName("Progress Report")]
      public string ProgressReport { get; set; }
  
      [Required]
      public int UserId { get; set; }
      public virtual User User { get; set; }
  
      [Required]
      public string PatientRegNo { get; set; }
      public virtual Patient Patient { get; set; }
  </code></pre>
  
  <p>My Department Controller</p>
  
  <pre><code>[HttpGet]
      public ActionResult AddDptCRP()
      {
          var user = (from p in userdb.Users
                      where p.UserType == "doctor"
                      select p.UserId).ToList();
          ViewBag.Userlist = new SelectList(user, "UserId");
          var patient = (from p in patientdb.Patients
                      where p.ReferDpt == "dptcrp"
                      select p.PatientRegNo).ToList();
          ViewBag.Patientlist = new SelectList(patient, "PatientRegNo");
          return View();
      }
  
      [HttpPost]
      public ActionResult AddDptCRP(DptCRP dptcrp)
      {
          try
          {
              if (ModelState.IsValid)
              {
                  dptdb.DptCRPs.Add(dptcrp);
                  dptdb.SaveChanges();
                  return RedirectToAction("ListDptCRP");
              }
              var user = (from p in userdb.Users
                          where p.UserType == "doctor"
                          select p.UserId).ToList();
              ViewBag.Userlist = new SelectList(user, "UserId");
              var patient = (from p in patientdb.Patients
                             where p.ReferDpt == "dptcrp"
                             select p.PatientRegNo).ToList();
              ViewBag.Patientlist = new SelectList(patient, "PatientRegNo");
              return View(dptcrp);
          }
          catch 
          {
              return View();
          }
      }
  </code></pre>
  
  <p>When i try to Add data in my DptCRP it shows error</p>
  
  <blockquote>
    <p>There is no ViewData item of type 'IEnumerable' that has the key 'Userlist'</p>
  </blockquote>
  
  <p>My AddDptCRP View Looks Like</p>
  
  <pre><code>@model FinalYear.Models.DptCRP
   @using (Html.BeginForm()) 
      {
      @Html.AntiForgeryToken()
      &lt;div class="form-horizontal"&gt;
          &lt;h4&gt;DptCRP&lt;/h4&gt;
          &lt;hr /&gt;
          @Html.ValidationSummary(true, "", new { @class = "text-danger" })
          &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model.ProvisionalDiagnosis, htmlAttributes: new { @class = "control-label col-md-2" })
              &lt;div class="col-md-10"&gt;
                  @Html.EditorFor(model =&gt; model.ProvisionalDiagnosis, new { htmlAttributes = new { @class = "form-control" } })
                  @Html.ValidationMessageFor(model =&gt; model.ProvisionalDiagnosis, "", new { @class = "text-danger" })
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model.ProgressReport, htmlAttributes: new { @class = "control-label col-md-2" })
              &lt;div class="col-md-10"&gt;
                  @Html.EditorFor(model =&gt; model.ProgressReport, new { htmlAttributes = new { @class = "form-control" } })
                  @Html.ValidationMessageFor(model =&gt; model.ProgressReport, "", new { @class = "text-danger" })
  
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.UserId, "UserId", htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.DropDownList("Userlist", null, htmlAttributes: new { @class = "form-control" })
              @Html.ValidationMessageFor(model =&gt; model.UserId, "", new { @class = "text-danger" })
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.PatientRegNo, "PatientRegNo", htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.DropDownList("Patientlist", null, htmlAttributes: new { @class = "form-control" })
              @Html.ValidationMessageFor(model =&gt; model.PatientRegNo, "", 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>