title: How do you bind a complex type containing a list in ASP.Net?
body: <p>So, I have a model like this:</p>
  <pre><code>public class EventViewModel
  {
      public string Title { get; set; }
      public List&lt;EventParticipant&gt; Participants { get; set; }
  }
  
  public class EventParticipant
  {
      [Key]
      public int Id { get; set; }
      public string Name { get; set; }
      public string Strength { get; set; }
      public string Losses { get; set; }
  
  }
  </code></pre>
  <p>and I have a form where I have a field for:</p>
  <ol>
  <li>Title</li>
  <li>Multiple participants</li>
  </ol>
  <pre><code>    &lt;form asp-controller=&quot;Event&quot; asp-action=&quot;Create&quot; method=&quot;post&quot;&gt;  
  
          &lt;input asp-for=&quot;Title&quot; class=&quot;form-controls/&gt;
                                  
          &lt;input asp-for=&quot;Participants[0].Name&quot; class=&quot;form-controls/&gt;                                
          &lt;input asp-for=&quot;Participants[0].Strength&quot; class=&quot;form-controls/&gt;      
          &lt;input asp-for=&quot;Participants[0].Losses&quot; class=&quot;form-controls/&gt;    
       
          &lt;input asp-for=&quot;Participants[1].Name&quot; class=&quot;form-controls/&gt;                                
          &lt;input asp-for=&quot;Participants[1].Strength&quot; class=&quot;form-controls/&gt;      
          &lt;input asp-for=&quot;Participants[1].Losses&quot; class=&quot;form-controls/&gt; 
           
          &lt;input type=&quot;submit&quot; class=&quot;form-controls/&gt;     
      &lt;/form&gt;
  </code></pre>
  <p>When I go to the page with the above code, I get the following error:</p>
  <pre><code>System.NullReferenceException: 'Object reference not set to an instance of an object.'
  </code></pre>
  <p>with the first &quot;Participants&quot; input being highlighted.</p>
  <p>How can I make it so that after posting, I can access a list of participants, like so:</p>
  <pre><code>    [HttpPost]
      [ValidateAntiForgeryToken]
      public ActionResult Create(EventViewModel model)
      {
          foreach (var participant in model.Participants)
          {
              Debug.WriteLine(&quot;Name: &quot; + participant.Name);
          }
          return RedirectToAction(&quot;Create&quot;);
      }
  </code></pre>