title: There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'CompanyID'
body: <p>I've been reading StackOverflow but nothing has really been able to help me with this. I'm working on a position model that has SelectLists for a fields from a couple other models, yet every time I try and save I get the error:   </p>
  
  <p><strong>"An exception of type 'System.InvalidOperationException' occurred in System.Web.Mvc.dll but was not handled in user code</strong></p>
  
  <p><strong>Additional information: There is no ViewData item of type 'IEnumerable' that has the key 'CompanyID'."</strong></p>
  
  <p>Here's the relevant code from my view:</p>
  
  <p><em>Views/Position/Create.cshtml</em></p>
  
  <pre><code>&lt;div class="form-group"&gt;
      &lt;label class="control-label col-md-2"&gt;Company&lt;/label&gt;
      &lt;div class="col-md-10"&gt;
          @Html.DropDownList("CompanyID", (SelectList)ViewBag.AllCompanies, new { @class = "form-control" })
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Here's the relevant code from my controller:  </p>
  
  <p><em>Controllers/PositionController.cs</em></p>
  
  <pre><code>        // GET: /Position/Create
          public ActionResult Create()
          {
              //create query to find all committees
              var query = from m in db.Majors
                          orderby m.Major
                          select m;
              //execute query and store in list
              List&lt;Majors&gt; allMajors = query.ToList();
  
              //convert list to select list format needed for HTML
              SelectList allMajorsList = new SelectList(allMajors, "MajorID", "Major");
  
              ViewBag.AllMajors = allMajorsList;
  
              //create query to find all committees
              var query2 = from c in db.Companies
                          orderby c.CompanyName
                          select c;
              //execute query and store in list
              List&lt;Company&gt; allCompanies = query2.ToList();
  
              //convert list to select list format needed for HTML
              SelectList allCompaniesList = new SelectList(allCompanies, "CompanyID", "CompanyName");
  
              ViewBag.AllCompanies = allCompaniesList;
  
              //create query to find all committees
              var query3 = from i in db.Industries
                           orderby i.IndustryName
                           select i;
              //execute query and store in list
              List&lt;Industry&gt; allIndustries = query3.ToList();
  
              //convert list to select list format needed for HTML
              SelectList allIndustriesList = new SelectList(allIndustries, "IndustryID", "IndustryName");
  
              ViewBag.AllIndustries = allIndustriesList;
  
              return View();
          }
  
      // POST: /Position/Create
      // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
      // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
      [HttpPost]
      [ValidateAntiForgeryToken]
      public ActionResult Create([Bind(Include="PositionID,PositionTitle,PositionType,PositionLocation,PositionDeadline,PositionDescription")] Position position, int[] SelectedMajors, Int32 CompanyID, Int32 IndustryID)
      {
          //find selected committee
          Company SelectedCompany = db.Companies.Find(CompanyID);
          Industry SelectedIndustry = db.Industries.Find(IndustryID);
  
          //associate committee with event
          position.PositionCompany = SelectedCompany;
          position.PositionIndustry = SelectedIndustry;
  
          if (ModelState.IsValid)
          {
  
              //if there are majors to add, add them
              if (SelectedMajors != null)
              {
                  foreach (int MajorId in SelectedMajors)
                  {
                      Majors majorToAdd = db.Majors.Find(MajorId);
                      position.ApplicableMajors.Add(majorToAdd);
                  }
              }
  
              db.Positions.Add(position);
              db.SaveChanges();
              return RedirectToAction("Index");
          }
  
          return View(position);
      }
  </code></pre>
  
  <p>I can't seem to figure out what I'm doing wrong. Any help would be greatly appreciated!</p>