title: Select rows and pass data(ID) to next view, MVC5 C#
body: <p>I have been trying to select multiple rows from my table of data(Generated using EF) and then pass all selected rows to the next view to perform some action. On passing the data to the next view i am getting the following error : </p>
  
  <blockquote>
    <p>System.NullReferenceException: 'Object reference not set to an instance of an object.'
    Temporary local of type 'int[]'> was null.</p>
  </blockquote>
  
  <p>Any help on how to solve this will be appreciated.</p>
  
  <p><strong>Below is my code:</strong></p>
  
  <p>View:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="row"&gt;
    &lt;div class="col-md-12"&gt;
      &lt;!-- Advanced Tables --&gt;
      &lt;div class="panel panel-default"&gt;
        &lt;div class="panel-heading"&gt;
          @using (Html.BeginForm()) {
          &lt;form action="#" method="post"&gt;
            &lt;label&gt;Search by Company Name:&lt;/label&gt; @Html.TextBox("SearchString")
            &lt;input type="submit" value="Go" placeholder="Search" style="background-color: #0a9dbd; color: white; border-color: #0a9dbd;"&gt; &amp;nbsp; &amp;nbsp;
            &lt;label&gt;Search by Card Number:&lt;/label&gt; @Html.TextBox("searchCard")
            &lt;input type="submit" value="Go" placeholder="Search" style="background-color: #0a9dbd; color: white; border-color: #0a9dbd;"&gt; &amp;nbsp; &amp;nbsp;
            &lt;a href="ExportToExcel"&gt;Export to Excel&lt;/a&gt;
          &lt;/form&gt;
  
          }
        &lt;/div&gt;
  
        &lt;div class="panel-body"&gt;
          &lt;a href="@Url.Action(" Create ","CustomerView ")" class="btn btn-primary"&gt;Add Gift Card&lt;/a&gt;
          &lt;a href="@Url.Action(" GetBalance ", "CustomerView ")" class="btn btn-primary"&gt;Get Card Balance&lt;/a&gt;
          &lt;a href="@Url.Action(" PostCards ", "CustomerView ")" class="btn btn-primary"&gt;Load Cards&lt;/a&gt;
  
          &lt;br /&gt;
          &lt;br /&gt;
          &lt;div class="table-responsive"&gt;
            &lt;table class="table table-striped table-bordered table-hover" id="dataTables-example"&gt;
              &lt;thead&gt;
                &lt;tr&gt;
                  &lt;th&gt;Card ID&lt;/th&gt;
                  &lt;th&gt;Company&lt;/th&gt;
                  &lt;th&gt;Card Number&lt;/th&gt;
                  &lt;th&gt;Card Number 2&lt;/th&gt;
                  &lt;th&gt;Date Created&lt;/th&gt;
                  &lt;th&gt;Card Status&lt;/th&gt;
                  &lt;th&gt;Discount Level ID&lt;/th&gt;
                  &lt;th&gt;Loyalty Level ID&lt;/th&gt;
                  &lt;th&gt;Gift Card Enabled&lt;/th&gt;
                  &lt;th&gt;Loyalty Enabled&lt;/th&gt;
                  &lt;th&gt;&lt;/th&gt;
  
                &lt;/tr&gt;
              &lt;/thead&gt;
              &lt;tbody&gt;
                @foreach (var item in Model) {
                &lt;tr&gt;
                  &lt;td&gt;&lt;input type="checkbox" name="ids" value="@item.CardID" /&gt;&lt;/td&gt;
                  &lt;td&gt;@item.CardID&lt;/td&gt;
                  &lt;td&gt;@item.Customer.CustomerCompanyName&lt;/td&gt;
                  &lt;td&gt;@item.CardNumber&lt;/td&gt;
                  &lt;td&gt;@item.CardNumber2&lt;/td&gt;
                  &lt;td&gt;@item.CardDate&lt;/td&gt;
                  &lt;td&gt;@item.CardStatus&lt;/td&gt;
                  &lt;td&gt;@item.DiscountLevelID&lt;/td&gt;
                  &lt;td&gt;@item.LoyaltyLevelID&lt;/td&gt;
                  &lt;td&gt;@item.GiftCardEnabled&lt;/td&gt;
                  &lt;td&gt;@item.LoyaltyEnabled&lt;/td&gt;
  
  
                  &lt;td&gt;
                    &lt;a href="@Url.Action(" Edit ","CustomerView ", new {id = item.CardID} )" class="btn btn-primary"&gt;&lt;i class="fa fa-edit "&gt;&lt;/i&gt; Edit&lt;/a&gt; &lt;br /&gt;
  
                  &lt;/td&gt;
  
                &lt;/tr&gt;
                }
              &lt;/tbody&gt;
  
            &lt;/table&gt;
            Page @(Model.PageCount
            &lt; Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount @Html.PagedListPager(Model, page=&gt; Url.Action("Index", new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }))
          &lt;/div&gt;
  
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;!--End Advanced Tables --&gt;
    &lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Controller:</p>
  
  <pre><code>public ActionResult PostCards(int[]ids)
          {
              var myObject = new Card();
  
              foreach(var id in ids)
              {
                  myObject = db.Cards.Single(o =&gt; o.CardID == id);
                  return RedirectToAction("LoadCards", myObject);
              }
  
              return View();
          }
  
  
          public ActionResult LoadCards()
          {
              return View();
          }
  </code></pre>
  
  <p>I need the selected data to be passed to the LoadCards view.</p>