I have this linq query
var impuestos = conceptos
.GroupBy(a => a.ImpuestoId)
.Select(a => new
{
id = a.Key,
montoImpuesto = a.Sum(b => b.montoImpuesto),
impuestoNombre = a.FirstOrDefault().impuesto.Nombre,
impuestoTipo = a.FirstOrDefault().impuesto.Tipo,
})
.ToList();
ViewBag.grupo = impuestos;
And I want to show it in a view. It tried this
@foreach (var impuesto in ViewBag.grupo)
{
<tr>
<td>
@impuesto.id
</td>
<td>
@impuesto.Nombre
</td>
<td>
@impuesto.montoImpuesto
</td>
</tr>
}
But I get an error telling there is no definition for 'id' in the object. I already tried adding a foreach inside the main foreach, but I get different errors. What is the correct way?