-1
Error starting query and generating list with 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.Provisioning],<>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.Sourcing]'.
Abastecimento 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>
Modelling:
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; }
}
Young man, note my issue in your question, this is the relevant code so that it can be answered. That’s all we need to reproduce the problem.
– Jéf Bueno
Now, try to edit the question and put the class code
BlogWeb.Models.Abastecimento
, please.– Jéf Bueno
@LINQ sorry, it’s just I thought it might be something up that could interfere, things up, I apologize
– Guilherme Padovam
No need to apologize, I’m just trying to instruct you
– Jéf Bueno
muder . Select(gp => new .... to . Select(gp => new Supply
– Marco Souza
@Marconciliosouza Where is the property
LitroTotal
in kindAbastecimento
? And the propertiesNumCarroId
andTotalConsumido
?– Jéf Bueno
@LINQ ... he’s actually creating an Anonymous type with different names than it really should be ... in the typed class. a view waits Supply and he pass an Anonymous ...
– Marco Souza
That, I know. The question I asked you was another. How to change the type of
Select
the same as the view will solve the problem? It will only cause more problem.– Jéf Bueno
@LINQ, we didn’t know that... sorry there .
– Marco Souza