title: Saving an IEnumerable Model
body: <p>I have a view that has 2 date pickers, one of which is a start date and the other of which is end date.  I am able to get the user to select the start and end dates, redirect to a view that will have a list of Time worked where the user could change the date, enter time, and once they are done they should be able to click the save button and it should create a new instance of each time worked to the database.  I got the view displaying with no problem, but when the form posts my enumerable model is null, the form collection only has one accessible item, and I am not sure why.  Please take a look at the view I am creating below to get an idea of what I am doing and let me know if you are able to help me in any way.  </p>
  
  <pre><code>@model IEnumerable&lt;TimeCollection.Models.TimeWorked&gt;
  
  @{
      ViewBag.Title = "Create TimeWorked Range";
  }
  
  &lt;h2&gt;Create TimeWorked Range&lt;/h2&gt;
  
  @using (Html.BeginForm()) {
      @Html.ValidationSummary(true)
  &lt;table&gt;
      &lt;tr&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.WorkDate)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.HoursWorked)
          &lt;/th&gt;
      &lt;/tr&gt;
  
  @foreach (var item in Model) {
      &lt;tr&gt;
          @Html.HiddenFor(modelItem =&gt; item.EmployeeId)
          &lt;td&gt;
              @Html.EditorFor(modelItem =&gt; item.WorkDate)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.EditorFor(modelItem =&gt; item.HoursWorked)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.HiddenFor(modelItem =&gt; item.BeenSubmitted)
          &lt;/td&gt;
      &lt;/tr&gt;
  }
  
  &lt;/table&gt;
      &lt;p&gt;
          &lt;input type="submit" value="Save" /&gt;
      &lt;/p&gt;
  }
  
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  
  namespace TimeCollection.Models
  {
      public class TimeWorked
      {
          public int TimeWorkedId { get; set; }
          public int EmployeeId { get; set; }
          public DateTime WorkDate { get; set; }
          public int HoursWorked { get; set; }
          public bool BeenSubmitted { get; set; }
  
          public static void CreateTimeWorked(TimeWorked timeWorkedToCreate)
          {
              string insertQuery = string.Format("insert into time_worked (employee_id, work_date, work_hours, been_submitted) values ('{0}', '{1}', '{2}', '{3}')", timeWorkedToCreate.EmployeeId, timeWorkedToCreate.WorkDate.ToString("yyyy/MM/dd"), timeWorkedToCreate.HoursWorked, (timeWorkedToCreate.BeenSubmitted == true ? "1" : "0"));
              SpectrumData.Utility.ExecuteMySqlCommand(SpectrumData.Properties.Resources.SpectrumTSDatabaseConnectionString, insertQuery);
          }
  
          public static TimeWorked ReadTimeWorked(int timeWorkedId)
          {
              string selectQuery = string.Format("select * from time_worked where time_worked_id = '{0}'", timeWorkedId);
              return ConvertDataRowIntoTimeWorked(SpectrumData.Utility.FillDataSet(SpectrumData.Properties.Resources.SpectrumTSDatabaseConnectionString, selectQuery).Tables[0].Rows[0]);
          }
  
          public static void UpdateTimeWorked(TimeWorked timeWorkedToUpdate)
          {
              string updateQuery = string.Format("update time_worked set work_date = '{0}', work_hours = '{1}', been_submitted = '{2}' where time_worked_id = '{2}'", timeWorkedToUpdate.WorkDate, timeWorkedToUpdate.HoursWorked, timeWorkedToUpdate.BeenSubmitted, timeWorkedToUpdate.TimeWorkedId);
              SpectrumData.Utility.ExecuteMySqlCommand(SpectrumData.Properties.Resources.SpectrumTSDatabaseConnectionString, updateQuery);
          }
  
          public static void DeleteTimeWorked(int timeWorkedId)
          {
              string deleteQuery = string.Format("delete from time_worked where time_worked_id = '{0}'", timeWorkedId);
              SpectrumData.Utility.ExecuteMySqlCommand(SpectrumData.Properties.Resources.SpectrumTSDatabaseConnectionString, deleteQuery);
          }
  
          private static TimeWorked ConvertDataRowIntoTimeWorked(System.Data.DataRow timeWorkedDataRow)
          {
              TimeWorked timeWorked = new TimeWorked();
              timeWorked.BeenSubmitted = (timeWorkedDataRow["been_submitted"].ToString() == "1" ? true : false);
              timeWorked.EmployeeId = int.Parse(timeWorkedDataRow["employee_id"].ToString());
              timeWorked.HoursWorked = int.Parse(timeWorkedDataRow["work_hours"].ToString());
              timeWorked.TimeWorkedId = int.Parse(timeWorkedDataRow["time_worked_id"].ToString());
              timeWorked.WorkDate = DateTime.Parse(timeWorkedDataRow["work_date"].ToString());
  
              return timeWorked;
          }
      }
  }
  
   public ActionResult CreateTimeWorkedRange(DateTime startDate, DateTime endDate)
      {
          List&lt;Models.TimeWorked&gt; listOfTimeWorked = new List&lt;Models.TimeWorked&gt;();
          DateTime beginning = startDate;
          DateTime ending = endDate;
  
          while (beginning &lt;= ending)
          {
              Models.TimeWorked dayWorked = new Models.TimeWorked()
              {
                  EmployeeId = (Session["InventoryReviewUser"] as SpectrumData.SpectrumTS.InventoryReviewUser).EmployeeId,
                  WorkDate = beginning
              };
  
              if (listOfTimeWorked.Contains(dayWorked) == false)
              {
                  listOfTimeWorked.Add(dayWorked);
              }
  
              beginning = beginning.AddDays(1);
          }
  
          return View(listOfTimeWorked);
      }
  
      [HttpPost]
      public ActionResult CreateTimeWorkedRange(List&lt;Models.TimeWorked&gt; modelList)
      {
          foreach (Models.TimeWorked timeWorked in modelList)
          {
              Models.TimeWorked.CreateTimeWorked(timeWorked);
          }
      }
  </code></pre>