title: Object reference not set to an instance of an object. Custom object returning null when POST
body: <p>I'm trying to create a list of objects in my view, but in the post method, the parameter coming in is null.  The create page loads fine with all the information I want, but when I click "Create" I get the error listed in my title. What can I be doing wrong?</p>
  
  <blockquote>
    <p>Employees have an availability linked to them for each day. That's what i am trying to achieve</p>
  </blockquote>
  
  <p><strong>Model</strong></p>
  
  <pre><code>public class Availability
  {
  
      [Required]
      public long Id { get; set; }
  
      [Required]
      [DataType(DataType.Text)]
      [Display(Name = "Weekday")]
      public string weekday { get; set; }
  
      [DataType(DataType.Time)] 
      [Display(Name = "Start Time")]
      public DateTime StartTime { get; set; }
  
      [DataType(DataType.Time)]
      [Display(Name = "End Time")]
      public DateTime EndTime { get; set; }
  
      public virtual Employee employee { get; set; }
  
  }
  }
  </code></pre>
  
  <p><strong>Custom Class</strong></p>
  
  <pre><code>public class SetAvailability
  {
      public long EmpID { get; set; }
      public String firstName {get; set;}
      public String lastName { get; set; }
      public Availability availability {get; set;}
  
  
  }
  </code></pre>
  
  <p><strong>Controller methods</strong></p>
  
  <pre><code>// GET: /Availability/Create
  
      public ActionResult  Create(long id)
      {
          string[] weekdays ={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
          //find the employee
          Employee emp = db.Employees.Find(id);
  
          //create a list of setAvailability objects for each day 
          List&lt;SetAvailability&gt; editor = new List&lt;SetAvailability&gt;();
  
  
          //instantiate each SetAvailability object and populate accordingly for 7 days
          for (int i = 0; i &lt; 7; i++)
          {
              //create a blank SetAvilability
              var _editor = new SetAvailability();
  
              //create a blank availability
              _editor.availability = new Availability();
  
              //set the weekday 
              _editor.availability.weekday = weekdays[i].ToString();
  
              //set the employee id, first name and last name
              _editor.EmpID = emp.Id;
              _editor.firstName = emp.FirstName;
              _editor.lastName = emp.LastName;
              //add the _editor to the editorlist
              editor.Add(_editor);
          }
  
          return View(editor);
  
  
      }
  
      //
      // POST: /Availability/Create
  
      [HttpPost]
      public ActionResult Create(List&lt;SetAvailability&gt; dto)
      {
          //dto object is coming in null! (checked by debugging) 
          List&lt;SetAvailability&gt; temp = new List&lt;SetAvailability&gt;();
          temp = dto;
  
          if (ModelState.IsValid)
          {
              // set the values for each availability object 
              //    breaks here!
              foreach (var item in dto)
              {                    
                  // get the employee
                  item.availability.employee = db.Employees.Find(item.EmpID);
  
                  // weekday should already be set
                  // start and end times should come in from the create view
  
                  db.Availability.Add(item.availability);
              }
              db.SaveChanges();
              return RedirectToAction("Index","employee");
          }
  
          return View(temp);
      }
  </code></pre>
  
  <p><strong>View</strong></p>
  
  <pre><code>@model List&lt;VolumeV2.Models.DTOs.SetAvailability&gt;
  
  @{
  ViewBag.Title = "Create";
  
  }
  
  &lt;h2&gt;Create&lt;/h2&gt;
  
  @using (Html.BeginForm()) {
  @Html.ValidationSummary(true)
  
  &lt;fieldset&gt;
      &lt;legend&gt;Availability&lt;/legend&gt;
  
      &lt;table&gt;
          &lt;tr&gt;
          @foreach (var item in Model)                
              {               
                      @Html.HiddenFor(model =&gt; item.EmpID)
                      @Html.HiddenFor(model =&gt; item.firstName)
                      @Html.HiddenFor(model =&gt; item.lastName)
              &lt;td&gt;
                 @Html.LabelFor(model =&gt; item.availability.weekday)
              &lt;/td&gt;                
              &lt;td&gt;
                 @Html.LabelFor(model =&gt; item.availability.StartTime)                
              &lt;/td&gt;
              &lt;td&gt;
                 @Html.LabelFor(model =&gt; item.availability.EndTime)                
              &lt;/td&gt;                
              break;
          }
          &lt;/tr&gt;
          @foreach (var item in Model){
                      @Html.HiddenFor(model =&gt; item.EmpID)
                      @Html.HiddenFor(model =&gt; item.firstName)
                      @Html.HiddenFor(model =&gt; item.lastName)
              &lt;tr&gt;
                  &lt;td&gt;
                  @Html.EditorFor(modelitem =&gt; item.availability.weekday)
                  @Html.ValidationMessageFor(modelitem =&gt; item.availability.weekday)
                  &lt;/td&gt;
  
                  &lt;td&gt;                           
                  @Html.EditorFor(modelitem =&gt; item.availability.StartTime)
                  @Html.ValidationMessageFor(modelitem =&gt; item.availability.StartTime)
                  &lt;/td&gt;
  
                  &lt;td&gt;                          
                  @Html.EditorFor(modelitem =&gt; item.availability.EndTime)
                  @Html.ValidationMessageFor(modelitem =&gt; item.availability.EndTime)
                  &lt;/td&gt;
             &lt;/tr&gt;
          }
      &lt;/table&gt;
      &lt;p&gt;
          &lt;input type="submit" value="Create" /&gt;
      &lt;/p&gt;
  &lt;/fieldset&gt;
  }
  
  &lt;div&gt;
  @Html.ActionLink("Back to List", "Index")
  &lt;/div&gt;
  
  @section Scripts {
  @Scripts.Render("~/bundles/jqueryval")
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/iaCyl.png" alt="enter image description here"></p>