title: Accessing list properties in the typed view from a Viewmodel
body: <p>I have a master view model, with the following two lists that are from two different DB tables, </p>
  
  <pre><code>public IEnumerable &lt;Customer&gt; SomeCustomer { get; set; }
  public IEnumerable &lt;CustomerSite&gt; CustomerSites { get; set; }
  </code></pre>
  
  <p>In my controller I have</p>
  
  <pre><code>public ViewResult Index()
  {
      masterViewModel sitesModel = new masterViewModel();
      return View(sitesModel);
  }
  </code></pre>
  
  <p>Then in my view I write</p>
  
  <pre><code>@model IEnumerable&lt;trsDatabase.Models.masterViewModel&gt;
  </code></pre>
  
  <p>If I try to access the model by using a for each statement</p>
  
  <pre><code>@foreach (var customer in Model)
  </code></pre>
  
  <p>When I type @customer. It will only let me access the two lists not the individual properties in the list.</p>
  
  <p>I thought I would have been able to do this with e.g. </p>
  
  <pre><code>@customer.CustomerSites.UnitNo
  </code></pre>
  
  <p>But the furthest i can go is </p>
  
  <pre><code>@customer.CustomerSites
  </code></pre>
  
  <p>And this obviously will not let me access the individual properties in the lists</p>
  
  <p>Does anyone have any ideas on what I'm doing wrong here? Do I need to define the properties from the viewmodel in the controller? (I think not)</p>
  
  <p><strong>Update</strong></p>
  
  <p>I have the following code in my viewmodel, </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>Then the following in the controller, </p>
  
  <pre><code>public ViewResult Index()
  {
      masterViewModel sitesModel = new masterViewModel();
      return View(sitesModel);
  }
  </code></pre>
  
  <p>Then I changed my view declaration to </p>
  
  <pre><code>@model trsDatabase.Models.masterViewModel
  </code></pre>
  
  <p>This allows me to access the properties from the view perfectly, but it throws an error with the foreach loop as it can't be used when the view is inheriting the model rather than the Ienumerable list, do I need to change the syntax for rendering the list in the view and use something other than a foreachloop?</p>