title: Why doesn't my SelectList like contents of my IList?
body: <p>Here is the relevant code in my Razor page: I get an error message stating that the object (on the select element line) was not set to an instance of an object.</p>
  <pre><code>&lt;select asp-for=&quot;EmployeeLocation.EmployeeID&quot; asp-items=&quot;@Model.EmployeeSelectList&quot;&gt;
  </code></pre>
  <p>Here is the relevant code in my PageModel class:</p>
  <pre><code>public EmployeeLocation EmployeeLocation { get; set; }
  public Employee Employee { get; set; }
  
  public class JoinResult
  {
      public int EmployeeID;
      public string LastName;
  }
  private IQueryable&lt;JoinResult&gt; JoinResultIQueryable;
  private IList&lt;JoinResult&gt; JoinResultIList;
  public SelectList EmployeeSelectList;
  
  public async Task OnGetAsync()
  {
  
      // Get the employee's locations.
      List&lt;int&gt; EmployeeLocationsList = HttpContext.Session.GetObject&lt;List&lt;int&gt;&gt;(&quot;EmployeeLocationsList&quot;);
  
      // Populate the employee select list.
  
      JoinResultIQueryable = (
          from e in IDDSContext.Employee
          join p in IDDSContext.Position on e.PositionID equals p.PositionID
          join el in IDDSContext.EmployeeLocation on e.EmployeeID equals el.EmployeeID
          where e.Active == true
              &amp;&amp; e.PositionID != 1 // Do not display the super administrator's data.
              &amp;&amp; EmployeeLocationsList.Contains(el.LocationID)
          select new JoinResult
          {
              EmployeeID = e.EmployeeID,
              LastName = e.LastName
          });
  
      JoinResultIList = await JoinResultIQueryable
          .Distinct()
          .OrderBy(jr =&gt; jr.LastName)
          .ToListAsync();
  
      // Display the results in the Output window. Just done to show contents of JoinResultIList (see below).
      foreach (var item in JoinResultIList)
      {
          Debug.WriteLine(&quot;[&quot; + item.EmployeeID + &quot;][&quot; + item.LastName + &quot;]&quot;);
      }
  
      // ***** The problem seem to occur here. Evidently, the SelectList doesn't like contents of the IList. Why is this happening?
      EmployeeSelectList = new SelectList(JoinResultIList, &quot;EmployeeID&quot;, &quot;LastName&quot;);
  
  }
  </code></pre>
  <p>Here are the contents of JoinResultIList (in the Output window):</p>
  <pre><code>[4][Anderson (OH)]
  [30][Becon (OH)]
  [26][Smith (OH)]
  [25][Stevens (OH)]
  </code></pre>