It is giving error when starting the query and in the generation of the list with the results:
Error:
System.InvalidOperationException: The model item passed into the dictionary is of type 'System.Linq.Enumerable + WhereSelectEnumerableIterator' 2 [System.Linq.IGrouping'2 [System.Int32, BlogWeb.Models.Hashing], < & gt ; f__AnonymousType1'3 [System.Int32, System.Int32, System.Decimal]] ', but this dictionary requires a model item of type' System.Collections.Generic.IList'1 [BlogWeb.Models.Hashing] '.
Supply Controller:
public ActionResult AbastecimentoResumo()
{
//código irrelevante
var resultado = consulta.GroupBy(c => c.NumCarro.NCarro)
.Select(gp => new
{
NumCarroId = gp.Key,
LitroTotal = gp.Sum(c => c.Litro),
TotalConsumido = gp.Sum(c => c.TotalGasto)
});
// código irrelevante
return View(resultado);
}
My view :
@using PagedList.Mvc;
@model IList<BlogWeb.Models.Abastecimento>
@{ ViewBag.Title = "Relatório de Vendas";
Layout = "~/Views/Shared/_Layout.cshtml"; }
<table id="customers">
<tr>
<th>N° Carro </th>
<th>Quant. </th>
<th>Valor Unitário </th>
</tr>
@{
foreach (var a in Model)
{
<tr>
<td> @a.NumCarro.NCarro </td>
<td> @a.Litro</td>
<td> @a.TotalGasto</td>
</tr>
}
}
</table>
ModelAccess:
public class Abastecimento
{
public virtual int Id { get; set;}
[Required]
public virtual int Litro { get; set; }
public virtual DateTime? DtAbastecido { get; set; }
public virtual decimal VlrUnit { get; set; }
public virtual int Km { get; set; }
public virtual decimal TotalGasto { get; set; }
public virtual int Km_Andado { get; set; }
public virtual Usuario Autor { get; set; }
public virtual Compra NomeProduto { get; set; }
public virtual Veiculo NumCarro { get; set; }
}