title: How can I bind complex Lists in ASP.NET Core RazorPages
body: <p>I'm new to ASP.NET Core Razor Pages. I try to retrieve a List&lt;> from a Page via POST. If I bind primitive Data types, I didn't face any problems. However, If I want to pass data from my Page to the Server, which contains a List I got trouble. I was able to pass the data from the server to the client, but not back.</p>
  
  <p>This is an extract from my Code:</p>
  
  <p>The RazorPage:</p>
  
  <pre><code>&lt;form method="post"&gt;
      &lt;table class="table"&gt;
          &lt;thead&gt;
              &lt;tr&gt;
                  &lt;th&gt;
                      @Html.DisplayNameFor(model =&gt; model.Positions[0].Number)
                  &lt;/th&gt;
                  &lt;th&gt;
                      @Html.DisplayNameFor(model =&gt; model.Positions[0].IsSelected)
                  &lt;/th&gt;
              &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
              @if (!(Model.Positions is null))
              {
                  @foreach (var item in Model.Positions)
                  {
                      &lt;tr&gt;
                          &lt;td&gt;
                              @Html.DisplayFor(modelItem =&gt; item.Number)
                          &lt;/td&gt;
                          &lt;td&gt;
                              @Html.CheckBoxFor(modelItem =&gt; item.IsSelected)
                          &lt;/td&gt;
                      &lt;/tr&gt;
                  }
              }
          &lt;/tbody&gt;
      &lt;/table&gt;
      &lt;input type="submit" /&gt;
  </code></pre>
  
  <p>The Backend C#-file:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel.DataAnnotations;
  using System.Linq;
  using System.Threading.Tasks;
  using Project.Models;
  using Microsoft.AspNetCore.Mvc;
  using Microsoft.AspNetCore.Mvc.RazorPages;
  using Microsoft.AspNetCore.Mvc.Rendering;
  using Microsoft.EntityFrameworkCore;
  
  namespace Project.Pages
  {
      public class TestModel : PageModel
      {
          private readonly DBContext _context;
  
  
          [FromRoute]
          public int? Id { get; set; }
          public List&lt;SelectListItem&gt; CustomerOrder { get; set; } = new List&lt;SelectListItem&gt;();
          [BindProperty]
          public string SelectedNumber { get; set; }
          [BindProperty]
          public List&lt;Position&gt; Positions { get; set; }
          public TestModel(Project.Models.DBContext context)
          {
              _context = context;
          }
          public void OnGet()
          {
              if (!(Id is null))
              {
                  _context.CustomerOrder.Select(co =&gt; co.OrderNumber).Distinct().ToList().ForEach(y =&gt; CustomerOrder.Add(new SelectListItem(text: y, value: y)));
              }
          }
  
          public async Task OnPostAsync()
          {
              if (!(SelectedNumber is null))
              {
                  string s = $@"
                  select * from Table1 xyz where xyz.Column1 in (
                      SELECT distinct Column1
                      FROM Table1
                      where value = '" + SelectedNumber + "') and xyz.name = 'SLLZ'";
  
                  var res = await _context.Table1.FromSql(s).Select(x =&gt; x.ValueDescription).Distinct().OrderBy(x =&gt; x).ToListAsync();
  
                  Positions = new List&lt;Position&gt;();
                  foreach (var item in res)
                  {
                      Positions.Add(new Position { Number = item });
                  }
  
  
              }
              _context.CustomerOrder.Select(co =&gt; co.OrderNumber).Distinct().ToList().ForEach(y =&gt; CustomerOrder.Add(new SelectListItem(text: y, value: y)));
  
          }
      }
      public class Position
      {
          public string Number { get; set; }
          public bool IsSelected { get; set; }
      }
  }
  </code></pre>
  
  <p>If I set a Breakpoint at the beginning of the OnPost-Method, I would expect the List to be filled with the IsSelected-Property related to the user's input in the checkbox, but it isn't.</p>