title: How to Pass a List of Items from View to Controller (ASP.NET MVC 4)
body: <p>I'm trying to pass multiple <strong>items</strong> of type <strong>List&lt;item&gt;</strong> to my controller, however, when I submit my data, it show as null in my controller.</p>
  
  <p>What I would like to happen is that I have a list of 'expenses' in the View, and beside each 'expense' or item is a checkbox from the <strong>Submitted</strong> Boolean property in my Model. When I check the items, I would like the list of checked items' properties <strong>Submitted</strong> and <strong>DateSubmitted</strong> to be updated in the database.</p>
  
  <p><strong>@Html.DisplayFor(modelItem => item.Submitted)</strong> in the View produces checkboxes.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>Here is my View:</p>
  
  <pre><code>@model IEnumerable&lt;Expenses.Models.Expense&gt;
  
  @{
  ViewBag.Title = "Submit Expenses";
  Layout = "~/Views/Shared/_Layout.cshtml";
  
  DateTime today = DateTime.Today;
  string formattedDate = today.ToString("MM/dd/yyyy");
  }
  
  &lt;link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"&gt;
  &lt;script src="//code.jquery.com/jquery-1.10.2.js"&gt;&lt;/script&gt;
  &lt;script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"&gt;&lt;/script&gt;
  
  &lt;h2&gt;Submit Expenses&lt;/h2&gt;
  
  @using (Html.BeginForm())
  {
  @Html.AntiForgeryToken()
  &lt;div class="form-inline"&gt;
      &lt;div class="form-group"&gt;
          &lt;h4&gt;Start Date:&lt;/h4&gt;
          &lt;div class="col-md-10"&gt;
              @Html.TextBox("expenseDate", formattedDate, htmlAttributes: new
             {
                 @class = "form-control"
             })
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          &lt;h4&gt;End Date:&lt;/h4&gt;
          &lt;div class="col-md-10"&gt;
              @Html.TextBox("expenseDate2", formattedDate, htmlAttributes: new
             {
                 @class = "form-control"
             })
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @if (User.IsInRole("admin"))
          {
              &lt;h4&gt;Username:&lt;/h4&gt;
              &lt;div class="editor-field"&gt;
                  @Html.DropDownList("UserId", String.Empty)
              &lt;/div&gt;
          }
      &lt;/div&gt;
  
      &lt;br /&gt;
      &lt;br /&gt;
  
      &lt;div class="form-group"&gt;
          &lt;div class="col-md-2"&gt;
              &lt;input type="submit" value="Retrieve Expenses" class="btn btn-default" /&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
  &lt;/div&gt;
  
  &lt;br /&gt;
  &lt;br /&gt;
  
  
  &lt;p&gt;
      @Html.ActionLink("Create New", "Create")
  &lt;/p&gt;
  &lt;table style="margin-bottom: 20px;"&gt;
      &lt;tr&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.Company)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.Category)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.Province)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.ReceiptName)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.Comment)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.GrossAmount)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.TaxAmount)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.NetAmount)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.Mileage)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.TravelStatus)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.LunchLearnStatus)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.WithClientStatus)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.DateEntered)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.DateSubmitted)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.ExpenseDate)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.ImageName)
          &lt;/th&gt;
          @if (User.IsInRole("admin"))
          {
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.UserProfile.UserName)
              &lt;/th&gt;
          }
          &lt;th&gt;&lt;/th&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;
              &lt;b&gt;Select All:&lt;/b&gt;
              &lt;br /&gt;
              &lt;input type="checkbox" name="expense" value="Expense" id="selectAllCheckboxes" class="expenseCheck"&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      @foreach (var item in Model)
      {
          &lt;tr&gt;
              &lt;td class="submitCheck"&gt;
                  @Html.EditorFor(modelItem =&gt; item.Submitted)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.Company)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.Category)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.Province)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.ReceiptName)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.Comment)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.GrossAmount)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.TaxAmount)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.NetAmount)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.Mileage)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.TravelStatus)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.LunchLearnStatus)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.WithClientStatus)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.DateEntered)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.DateSubmitted)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.ExpenseDate)
              &lt;/td&gt;
              &lt;td&gt;
                  @if (item.ImageName != null)
                  {
                      &lt;a href="~/Images/@Html.DisplayFor(modelItem =&gt; item.UserProfile.FullName)/@Html.DisplayFor(modelItem =&gt; item.ImageName)" class="imageClick" target="_blank"&gt;&lt;img src="~/Images/@Html.DisplayFor(modelItem =&gt; item.UserProfile.FullName)/@Html.DisplayFor(modelItem =&gt; item.ImageName)" alt="Image" style="width:80%" /&gt;&lt;/a&gt;
                  }
              &lt;/td&gt;
              @if (User.IsInRole("admin"))
              {
                  &lt;td&gt;
                      @Html.DisplayFor(modelItem =&gt; item.UserProfile.UserName)
                  &lt;/td&gt;
              }
              &lt;td&gt;
                  @Html.ActionLink("Edit", "Edit", new { id = item.ExpenseId }) |
                  @Html.ActionLink("Details", "Details", new { id = item.ExpenseId }) |
                  @if (User.IsInRole("admin"))
                  {
                      @Html.ActionLink("Delete", "Delete", new { id = item.ExpenseId })
                  }
  
              &lt;/td&gt;
          &lt;/tr&gt;
      }
  
  &lt;/table&gt;
  
   @Html.ActionLink("Submit Expenses", "SubmitExpenses", "Expenses", null, new { @class = "submitLink", @style = "background-color: #d3dce0; border: 1px solid #787878; cursor: pointer; font-size: 1.5em; font-weight: 600; margin-right: 8px; padding: 7px; width: auto; text-decoration: none; font-weight:bold;"})
  
  &lt;div class="ExportSection" style="margin-top:30px;"&gt;
      @*&lt;a href="javascript:void(0)"&gt;Export To CSV&lt;/a&gt;*@
      @Html.ActionLink("Export To CSV", "ExportExpensesListToCSV")
  &lt;/div&gt;
  }
  
  @section scripts {
  &lt;script type="text/javascript"&gt;
  
  
      $("#selectAllCheckboxes").click(function () {
          $('.submitCheck input:checkbox').not(this).prop('checked', this.checked);
      });
  
      $(function () {
          $("#expenseDate").datepicker();
      });
  
      $(function () {
          $("#expenseDate2").datepicker();
      });
  
  &lt;/script&gt;
  
  }
  </code></pre>
  
  <p>and here is my Controller method:</p>
  
  <pre><code>public ActionResult SubmitExpenses(List&lt;Expense&gt; expenses, DateTime? expenseDate = null, DateTime? expenseDate2 = null, int? userId = 0)
      {
          expenseDate = (DateTime)Session["FirstDate"];
          expenseDate2 = (DateTime)Session["SecondDate"];
  
          if (expenseDate == null || expenseDate2 == null)
          {
              expenseDate = DateTime.Now.AddMonths(-1);
              expenseDate2 = DateTime.Today;
          }
  
          string currentUserId = User.Identity.Name;
  
          var query = from e in db.Expenses
                      join user in db.UserProfiles on e.UserId equals user.UserId
                      where e.ExpenseDate &gt;= expenseDate &amp;&amp; e.ExpenseDate &lt;= expenseDate2 &amp;&amp; e.DateSubmitted == null
                      orderby e.ExpenseDate descending
                      select new { e, user };
  
          if (User.IsInRole("admin") &amp;&amp; userId != 0)
          {
              query = query.Where(x =&gt; x.user.UserId == userId);
          }
          else if (!User.IsInRole("admin"))
          {
              query = query.Where(x =&gt; x.user.UserName == currentUserId);
          }
  
          var expensesFromView = expenses;
  
          var joined = from dbExpense in query.Select(x =&gt; x.e).AsEnumerable()
                       join localExpense in expenses on dbExpense.ExpenseId equals localExpense.ExpenseId
                       where localExpense.Submitted
                       select dbExpense;
  
          foreach (Expense exp in joined)
          {
              exp.DateSubmitted = DateTime.Today;
          }
  
          try
          {
              db.SaveChanges();
              return RedirectToAction("Index");
          }
          catch (Exception e)
          {
              Console.WriteLine(e);
              return RedirectToAction("Submit");
          }
  
      }
  </code></pre>
  
  <p>Here is my model:</p>
  
  <pre><code>[Key]
      [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
      public int ExpenseId { get; set; }
  
      [Required]
      public string Company { get; set; }
  
      [Required]
      public string Category { get; set; }
  
      [Required]
      [Display(Name = "Receipt Name")]
      public string ReceiptName { get; set; }
      public string Comment { get; set; }
  
      [Required]
      public string Province { get; set; }
  
      [Required]
      [Display(Name = "Gross Amount")]
      public decimal GrossAmount { get; set; }
  
      [Required]
      [Display(Name = "GST/HST Amount")]
      public decimal TaxAmount { get; set; }
  
      [Required]
      [Display(Name = "Net Amount")]
      public decimal NetAmount { get; set; }
  
      [Display(Name = "Mileage (in Kilometers)")]
      public int Mileage { get; set; }
  
      [Display(Name = "Travelling?")]
      public bool TravelStatus { get; set; }
  
      [Display(Name = "Lunch &amp; Learn?")]
      public bool LunchLearnStatus { get; set; }
  
      [Display(Name = "With Clients?")]
      public bool WithClientStatus { get; set; }
  
      [DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}")]
      [Required]
      [Display(Name = "Date Entered")]
      public DateTime? DateEntered{ get; set; }
  
      [DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}")]
      [Display(Name = "Date Submitted")]
      public DateTime? DateSubmitted { get; set; }
  
      [DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}")]
      [Required]
      [Display(Name = "Expense Date")]
      public DateTime? ExpenseDate { get; set; }
  
      [Display(Name = "Image")]
      public string ImageName { get; set; }
  
      [Display(Name = "Submitted?")]
      public bool Submitted { get; set; }
  
      [Required]
      [Display(Name = "Name")]
      public int UserId { get; set; }
      [ForeignKey("UserId")]
      public virtual UserProfile UserProfile { get; set; }
  </code></pre>
  
  <p>My variable <code>expensesFromView</code> is showing as null and as a result, I get an error on my <code>joined</code> query that says: </p>
  
  <blockquote>
    <p><strong>Value cannot be null. Parameter name: inner</strong></p>
  </blockquote>