1
Well, I’m having a little bit of a problem here. I consult at the bank using Lambda
, and use the tag GroupBy
,query is bringing objects correctly, the problem, is that I can’t show in view. gives an error when I use IEnumerable<>
and when I try to use List
bug tbm. however, if I don’t use the GroupBy
, shows on screen, using the IEnumerable<>
, follows code:
Controller:
public ActionResult RelatorioDatadois(DateTime? dataInicio, DateTime? dataFim)
{
ViewBag.dataInicial = dataInicio;
ViewBag.dataFinal = dataFim;
if (dataInicio == null && dataFim == null)
{
return View();
}
else
{
var vrDb = db.VrDb.Where(v => v.DataSolicitacao >= dataInicio && v.DataSolicitacao <= dataFim && v.Situacao == Situacao.Finalizado).GroupBy(v => v.Veiculo.Id).ToList();
var data = dataInicio;
var dataF = dataFim;
return View(vrDb);
}
}
View:
@model IEnumerable<GaragemModel.Vr>
<div class="panel-heading">
<ul class="list-inline">
<li> <h4>Período:</h4></li>
<li>@ViewBag.dataInicial Até</li>
<li> @ViewBag.dataFinal</li>
</ul>
</div>
<table class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<th>
Placa
</th>
<th>
Descrição
</th>
<th>
Combustivel Gasto
</th>
<th>
Km Percorrido
</th>
<th>
Gasto
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr class="odd gradeX">
<td>
@Html.DisplayFor(modelItem => item.Veiculo.Placa)
</td>
<td>
@Html.DisplayFor(modelItem => item.Veiculo.Descricao)
</td>
<td>
@Html.DisplayFor(modelItem => item.Mv.Consumo) Litros
</td>
<td>
@Html.DisplayFor(modelItem => item.Mv.QuilometrosPercorridos) Km
</td>
<td>
R$ @ViewBag.TotalValorEmDinheiro
</td>
</tr>
}
</tbody>
</table>
The error When I use IEnumerable<>
:
The template item inserted in the dictionary is from type'System.Collections.Generic.List
1[System.Linq.IGrouping
2[System.Int32, Garagemmodel. Vr]', but this dictionary requires an item like 'System.Collections.Generic.Ienumerable`1[Garagemmodel.Vr]'.
I tried this way, however, the part where it is: g.Placa. g.Descricao... etc, from the error, because it does not have this property for the "g". appears only properties like g.Groupbu(), g.Tolist().. etc
– Rafael Passos