title: Invalid Operation Exception MVC C#
body: <p>I am very new to c# and MVC. I am trying to create a web application to make bookings for an Opticians practice. I have created my database using Code-First Entity Framework. On the create booking page I have a drop down where an Optician can be selected. When I created the create page using CRUD, the drop down showed the UserId, however I am trying to change that to a concat(FullName) of the Application Users(Optician) FirstName and LastName.</p>
  <p>Booking model:</p>
  <pre><code>public class Booking
  {
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public Guid BookingId { get; set; }
  
  
      [ForeignKey(&quot;Patient&quot;)]
      public Guid PatientId { get; set; }
      public virtual Patient Patient { get; set; }
  
      [ForeignKey(&quot;Practice&quot;)]
      public Guid PracticeId { get; set; }
      public virtual Practice Practice { get; set; }
  
      [ForeignKey(&quot;Optician&quot;)]
      public Guid OpticianId { get; set; }
      public virtual Optician Optician { get; set; }
  
      [Display(Name = &quot;Date&quot;)]
      [DataType(DataType.Date)]
      [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = &quot;{0:dd/MM/yyyy}&quot;)]
      public DateTime Date { get; set; }
  
      [ForeignKey(&quot;Time&quot;)]
      public Guid? TimeId { get; set; }
      public virtual Time Time { get; set; }
      
      public bool isAvail { get; set; }
  }
  </code></pre>
  <p>Identity Model:</p>
  <pre><code>public class ApplicationUser : IdentityUser
  {
      
      [Display(Name = &quot;First Name&quot;)]
      public string FirstName { get; set; }
  
      [Display(Name = &quot;Last Name&quot;)]
      public string LastName { get; set; }
  
      public string FullName
      {
          get
          {
              return this.FirstName + &quot; &quot; + this.LastName;
          }
      }
  </code></pre>
  <p>Optician:</p>
  <pre><code>    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public Guid OpticianId { get; set; }
  
      [ForeignKey(&quot;User&quot;)]
      public string UserId { get; set; }
      public virtual ApplicationUser User { get; set; }
  
      [ForeignKey(&quot;Practice&quot;)]
      public Guid PracticeId { get; set; }
      public virtual Practice Practice { get; set; }
  
      public virtual ICollection&lt;Booking&gt; Bookings { get; set; }
  
      public virtual ICollection&lt;Appointment&gt; Appointments { get; set; }
  }
  </code></pre>
  <p>Booking Controller:</p>
  <pre><code> // GET: Bookings/Create
      public ActionResult Create()
      {
          ViewBag.OpticianId = new SelectList(db.Opticans, &quot;OpticianId&quot;, &quot;UserId&quot;);
          ViewBag.PatientId = new SelectList(db.Patients, &quot;PatientId&quot;, &quot;HCN&quot;);
          ViewBag.PracticeId = new SelectList(db.Practices, &quot;PracticeId&quot;, &quot;PracticeName&quot;);
          ViewBag.TimeId = new SelectList(db.Times, &quot;TimeId&quot;, &quot;AppointmentTime&quot;);
          return View();
      }
  
      [HttpPost]
      [ValidateAntiForgeryToken]
      public ActionResult Create([Bind(Include = &quot;BookingId,PatientId,PracticeId,OpticianId,Date,TimeId,isAvail&quot;)] Booking booking)
      {
  
          // to ensure date is in the future
          if (ModelState.IsValidField(&quot;Date&quot;) &amp;&amp; DateTime.Now &gt; booking.Date)
          {
              ModelState.AddModelError(&quot;Date&quot;, &quot;Please enter a date in the future&quot;);
          }
          
          // Sets isAvail to false
          booking.isAvail = false;
  
          if (ModelState.IsValid)
          {
              booking.BookingId = Guid.NewGuid();
              db.Bookings.Add(booking);
              db.SaveChanges();
              return RedirectToAction(&quot;Index&quot;);
          }
  
          ViewBag.OpticianId = new SelectList(db.Opticans, &quot;OpticianId&quot;, &quot;FullName&quot;, booking.Optician.User.FullName);
          ViewBag.PatientId = new SelectList(db.Patients, &quot;PatientId&quot;, &quot;HCN&quot;, booking.PatientId);
          ViewBag.PracticeId = new SelectList(db.Practices, &quot;PracticeId&quot;, &quot;PracticeName&quot;, booking.PracticeId);
          ViewBag.TimeId = new SelectList(db.Times, &quot;TimeId&quot;, &quot;AppointmentTime&quot;, booking.TimeId);
          return View(booking);
      }
  </code></pre>
  <p>Create View:</p>
  <pre><code>&lt;div class=&quot;form-group&quot;&gt;
      @Html.LabelFor(model =&gt; model.Optician.User.FullName, &quot;FullName&quot;, htmlAttributes: new { @class = &quot;control-label col-md-2&quot; })
      &lt;div class=&quot;col-md-10&quot;&gt;
          @Html.DropDownList(&quot;FullName&quot;, null, htmlAttributes: new { @class = &quot;form-control&quot; })
          @Html.ValidationMessageFor(model =&gt; model.Optician.User.FullName, &quot;&quot;, new { @class = &quot;text-danger&quot; })
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  <p>I am getting the following exception:</p>
  <blockquote>
  <p>An exception of type 'System.InvalidOperationException' occurred in System.Web.Mvc.dll but was not handled in user code</p>
  <p>Additional information: There is no ViewData item of type 'IEnumerable' that has the key 'FullName'</p>
  </blockquote>
  <p>Any help would be greatly appreciated</p>