title: MVC Table values not displaying
body: <p><strong>Controller</strong></p>
  
  <pre><code>    public ActionResult Index(int? StaffID, int? id)
      {
          //var userEmail = User.Identity.Name;
          //var model = db.Staffs.Where(i =&gt; i.Email == userEmail).Include(x =&gt; x.Histories).Include(x =&gt; x.CurrentApplications).FirstOrDefault();
          //return View(model);
  
          var model = new LeaveIndexData();
          var userEmail = User.Identity.Name;
  
          model.Staffs = db.Staffs
              .Where(i =&gt; i.Email == userEmail);
  
          if(id != null)
          {
              ViewBag.StaffId = id.Value;
              model.CurrentApplications = model.Staffs
                  .Where(i =&gt; i.StaffID == id.Value).Single().CurrentApplication;
          }
  
          return View(model);
      }
  </code></pre>
  
  <p><strong>Index View</strong></p>
  
  <pre><code>@model test.ViewModel.LeaveIndexData
  
  @{
  ViewBag.Title = "Index";
  }
  
  
  @*&lt;table class="table"&gt;
  &lt;tr&gt;
      &lt;th&gt;Last Name&lt;/th&gt;
      &lt;th&gt;First Name&lt;/th&gt;
      &lt;th&gt;Hire Date&lt;/th&gt;
      &lt;th&gt;Office&lt;/th&gt;
      &lt;th&gt;Courses&lt;/th&gt;
      &lt;th&gt;&lt;/th&gt;
  &lt;/tr&gt;
  
  @foreach (var item in Model.Instructors)
  {
      string selectedRow = "";
      if (item.ID == ViewBag.InstructorID)
      {
          selectedRow = "success";
      }
      &lt;tr class="@selectedRow"&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.LastName)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.FirstMidName)*@
  
  &lt;p&gt;
      @Html.ActionLink("Create New", "Create")
  &lt;/p&gt;
  &lt;table class="table"&gt;
  @foreach (var item in Model.Staffs) {
      &lt;tr&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.AllocatedLeave)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.BalanceLeave)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.ActionLink("Edit", "Edit", new { id=item.StaffID }) |
              @Html.ActionLink("Details", "Details", new { id=item.StaffID }) |
              @Html.ActionLink("Delete", "Delete", new { id=item.StaffID })
          &lt;/td&gt;
      &lt;/tr&gt;
  }
  
  &lt;/table&gt;
  
  @if (Model.CurrentApplications != null)
  { 
  &lt;h2&gt;Current Applications&lt;/h2&gt;
  &lt;table class="table"&gt;
      &lt;tr&gt;
          &lt;th&gt;Start Date&lt;/th&gt;
          &lt;th&gt;End Date&lt;/th&gt;
          &lt;th&gt;Leave Type&lt;/th&gt;
          &lt;th&gt;Period&lt;/th&gt;
          &lt;th&gt;Application Status&lt;/th&gt;
          &lt;th&gt;Leave Reason&lt;/th&gt;
      &lt;/tr&gt;
  
      @foreach (var item in Model.CurrentApplications)
      {
          if(item.StaffID == ViewBag.StaffID)
          {
              &lt;tr&gt;
                  &lt;td&gt;@item.StartDate&lt;/td&gt;
                  &lt;td&gt;@item.EndDate&lt;/td&gt;
                  &lt;td&gt;@item.LeaveType&lt;/td&gt;
                  &lt;td&gt;@item.NoOfDays&lt;/td&gt;
                  &lt;td&gt;@item.AppStatus&lt;/td&gt;
                  &lt;td&gt;@item.LeaveReason&lt;/td&gt;
              &lt;/tr&gt;
          }
      }
  &lt;/table&gt;
  }
  </code></pre>
  
  <p><strong>Staff Class</strong></p>
  
  <pre><code>namespace test.Models
  {
  using System;
  using System.Collections.Generic;
  
  public partial class Staff
  {
      public int StaffID { get; set; }
      public string Name { get; set; }
      public string Email { get; set; }
      public Nullable&lt;decimal&gt; AllocatedLeave { get; set; }
      public Nullable&lt;int&gt; BalanceLeave { get; set; }
  
      public virtual History History { get; set; }
      public virtual ICollection&lt;CurrentApplication&gt; CurrentApplication { get; set; }
  }
  }
  </code></pre>
  
  <p>I cannot figure out why my Current Applications table isn't displaying. If I remove the line <code>@if (Model.CurrentApplications != null)</code>, I get this error:</p>
  
  <blockquote>
    <p>Object reference not set to an instance of an object</p>
  </blockquote>
  
  <p>Not sure if it's useful, but I'm using EntityFramework and my tables were generated from my database?</p>