title: How to make a Viewmodel of type IEnumerable?
body: <p>I am using the following code for a master view model that contains two lists of data, </p>
  
  <pre><code>namespace trsDatabase.Models
  {
      public class masterViewModel
      {
          public IEnumerable &lt;Customer&gt; Customers { get; set; }
          public IEnumerable &lt;CustomerSite&gt; CustomerSites { get; set; }
      }
  }
  </code></pre>
  
  <p>I am using the following code to pass the veiwmodel to the view, </p>
  
  <pre><code>public ViewResult Index()
  {
      masterViewModel sitesModel = new masterViewModel();
  
      return View(sitesModel);
  }
  </code></pre>
  
  <p>Then in my view I have the following, </p>
  
  <pre><code>@model IEnumerable&lt;trsDatabase.Models.masterViewModel&gt;
  
  foreach (var site in customer.CustomerSites)
  {
      foreach (var cust in customer.Customers)
      {
          &lt;tr&gt;
              &lt;td&gt;
                  @cust.CustomerName
              &lt;/td&gt;
              &lt;td&gt;
                  @site.UnitNo
              &lt;/td&gt;
  </code></pre>
  
  <p>using the above code I am able to access all properties from the two lists in the viewmodel, however when I navigate to the view I get an error as the view is expecting an IEnumerable. If I change the declaration to just pass the viewmodel </p>
  
  <pre><code>@model trsDatabase.Models.masterViewModel
  </code></pre>
  
  <p>the <code>foreach</code> statement won't work, it gives this error</p>
  
  <blockquote>
    <p>The model item passed into the dictionary is of type   'trsDatabase.Models.masterViewModel', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[trsDatabase.Models.masterViewModel]'.</p>
  </blockquote>
  
  <p>Can anyone offer any advice or point me in the right direction for resolving this, is it possible to make my viewmodel IEnumerable?</p>