title: How to show grouped data in ASP.NET MVC razor?
body: <p>I have this code in my controller:</p>
  
  <pre><code>var taxes = db.invoiceTaxes
      .Where(c =&gt; c.invoiceId == invoice.invoiceId)
      .GroupBy(row =&gt; new { row.TaxId, row.tax, row.percent, row.type })
      .Select(group =&gt; new { tax = group.Key.tax, percent = group.Key.percent, sum = group.Sum(s =&gt; s.sum), type = group.Key.type });
  
  ViewBag.taxes = taxes.ToList();
  </code></pre>
  
  <p>If I have this in my view</p>
  
  <pre><code>@foreach (var item in ViewBag.taxes)
  {
      @item
  }
  </code></pre>
  
  <p>I get </p>
  
  <blockquote>
    <p>{ tax = Facturacion.Models.Tax, percent = 16, sum = 31.36, type = False }</p>
  </blockquote>
  
  <p>But when I have </p>
  
  <pre><code>@foreach (var item in ViewBag.taxes)
  {
      @item.percent
  }
  </code></pre>
  
  <p>I get </p>
  
  <blockquote>
    <p>Object does not contain a definition for percent</p>
  </blockquote>
  
  <p>How can I show the fields my query returns? (In this case, the value "16")</p>
  
  <p>invoiceTaxes is not my model, it's Invoice</p>