title: Passing Model to Controller from View in ASP.NET MVC
body: <p>I'm working on my first application in ASP.NET MVC and have run into a snag that I cannot figure out, even after reading the entire internet. </p>
  
  <p>So I have several Views (they are reports) that are created with View Models, which are populated based on user selection criteria. I'm trying to build a method that accepts a Model and exports it in Excel format (using EPPlus), but the Model needs to be sent from one of these Views. This is somewhat of a functional/usability, rather than a technical requirement. A user can run reports, and after viewing the report, can click a button/link and an Excel version of the report they're looking at will be created. I want to pass the Model that the View that's being displayed is based on since the work has already been done to build this specific View Model based on the user's report selection criteria. </p>
  
  <p>This is all fine and good, and I can successfully pass a Model from a View that's displaying a report to the method that builds the report. All of the data in the View Model I pass seems to be there, except a collection of Models (IEnumerable) that is part of it. &lt;--That is where I'm stuck. The collection of IEnumerable has 0 items in it at breakpoint, but this is definitely not the case in when the View Model is created and passed into the View initially. </p>
  
  <p>I'm stuck--please help.</p>
  
  <p><strong>View Model:</strong> </p>
  
  <pre><code>public class ReportViewModel
  {
  
      public int ProjectId { get; set; }
  
      [Display(Name = "Project Name")]
      public string ProjectName { get; set; }
  
      [Display(Name = "Project #")]
      public string ProjectNumber { get; set; }
  
      public IEnumerable&lt;SystemModel&gt; SelectedSystems { get; set; }//has items when created and passed into the View intially, but not when the Model is passed from the View to the method/controller. 
  
      [Display(Name = "All Systems")]
      public bool AllSystems { get; set; }
  
      [Display(Name = "In Progress Systems")]
      public bool InProgressSystems { get; set; }
  
      [Display(Name = "Completed Systems")]
      public bool CompletedSystems { get; set; }
  
      [Display(Name = "Unchecked Systems")]
      public bool UncheckedSystems { get; set; }
  
      [Display(Name = "Systems with Problems - Ours")]
      public bool JciIssue { get; set; }
  
      [Display(Name = "Systems with Problems - Other's")]
      public bool OtherIssue { get; set; }
  
      [Display(Name = "Include Points with Problems")]
      public bool IncludePoints { get; set; }
  
  }
  </code></pre>
  
  <p><strong>View:</strong> </p>
  
  <pre><code>    @model ProjectOps_5.ViewModels.ReportViewModel
  
  
  @{
      ViewBag.Title = "Software Cx Status Report";
  }
  
  &lt;h2&gt;Software Cx Status Report&lt;/h2&gt;
  
  &lt;div&gt;
      &lt;div&gt;
          &lt;hr /&gt;
  
   @Html.ActionLink("Export to Excel", "ExportExcel", Model)//call to method
  
  //the report
  </code></pre>
  
  <p><strong>Method:</strong></p>
  
  <pre><code>    public void ExportExcel(ReportViewModel model)
          {
             //make Excel file
          }
  </code></pre>