title: Razor Pages SelectListItem not selected
body: <p>I’m working on an ASP.net Razor Page and having a problem with the tag-helper for a select-list.
  Especialy with the selected-property of the SelectListItem.</p>
  
  <p>I’ve got a list of Operating Systems from my database which one is assigned via a DeviceId to a device.</p>
  
  <p>When I fireup the Page I assume to have the “devicebound” operating system selected. The device id is published via int id by the Parameter of the OnGet-Method.</p>
  
  <p>This is the code to check if the device has an operating system bound. It will return the db-id of the operating system.</p>
  
  <pre><code>var SelectedOperatingSystemId = await _context.LicenseRelationships
                      .Include(lr =&gt; lr.License)
                      .ThenInclude(l =&gt; l.Software)
                      .Where(lr =&gt; lr.DeviceMetaDataId == id)
                      .Select(x =&gt; x.License.Software.Id)
                      .SingleOrDefaultAsync();
  </code></pre>
  
  <p>Here’s the debuggers output:
  <a href="https://i.stack.imgur.com/b0adC.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/b0adC.jpg" alt="enter image description here"></a></p>
  
  <p>After that I create an IEnumerable with this peace of code:</p>
  
  <pre><code>OpertaingSystemsList = await _context.Softwares
              .Where(s =&gt; s.IsOperatingSystem == true)
              .OrderBy(s =&gt; s.Name)
              .Select(s =&gt; new SelectListItem
              {
                  Value = s.Id.ToString(),
                  Text = s.Name,
                  Selected = s.Id == SelectedOperatingSystemId
              })
              .ToListAsync();
  </code></pre>
  
  <p>So, the option of the select should be selected when db-id equals the one’s of the variable SelectedOperatingSystemId. This is the Debugger’s output which is correct and what I was asuming:</p>
  
  <p><a href="https://i.stack.imgur.com/GFMP7.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GFMP7.jpg" alt="enter image description here"></a></p>
  
  <p>But here is the rendered code of the page. Value 2 should have been selected:</p>
  
  <p><a href="https://i.stack.imgur.com/T8FDB.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/T8FDB.jpg" alt="enter image description here"></a></p>
  
  <p>That’s the Html markup:</p>
  
  <pre><code>&lt;div class="form-group"&gt;
                  &lt;label asp-for="OperatingSystemId"&gt;&lt;/label&gt;
                  &lt;select asp-for="OperatingSystemId" asp-items="Model.OpertaingSystemsList" class="form-control"&gt;
                      &lt;option value=""&gt;Betriebssystem wählen&lt;/option&gt;
                  &lt;/select&gt;
              &lt;/div&gt;
  </code></pre>
  
  <p>I’ve no explanation for this behavior. Could it be a bug? Or does anybody see a mistake in my programming?
  Thanks, Patrick</p>