title: ASP.NET MVC View Model - How do I display data in the View?
body: <p>I'm learning ASP.NET MVC and it seems ViewModels are the recommended way of passing data from a Controller to a View and allowing for more than one Model to be used in a View. Therefore I've created ProductViewModel which has the following:</p>
  
  <pre><code>    public IEnumerable&lt;Product&gt; Products { get; set; }
      public IEnumerable&lt;ProductCategory&gt; ProductCategories { get; set; }
      public IEnumerable&lt;ProductDescription&gt; ProductDescriptions { get; set; }
  </code></pre>
  
  <p>In my controller I have:</p>
  
  <pre><code>        ProductViewModel productViewModel = new ProductViewModel();
          productViewModel.Products = db.Products.ToList();
          productViewModel.ProductDescription = db.ProductDescription.ToList();
  
          return View(productViewModel);
  </code></pre>
  
  <p>And the problem I'm having is looping over this data in the View. I can use <code>foreach</code> to iterate over for example <code>Products</code> but I don't know how to then combine this with <code>ProductDescription</code>:</p>
  
  <pre><code>@model Site.ViewModels.ProductListingViewModel
  @foreach (var item in Model.Products)
  {
      &lt;tr&gt;
          &lt;td&gt;
             @Html.DisplayFor(m =&gt; item.Name)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.DisplayFor(m =&gt; item.ProductID)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.DisplayFor(m =&gt; item.Color)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.DisplayFor(m =&gt; item.Description???) - What do I actually need to write?
          &lt;/td&gt;
      &lt;/tr&gt;
  }
  </code></pre>
  
  <p>Because the Description column is in <code>ProductDescription</code> it can't simply be accessed with <code>item.Description</code> because <code>item</code> specifically refers to <code>Products</code>. How should I do this?</p>