我在 c# 中创建了一个列表,以在 html 中按类别显示总值。Infelizmente, ele está dobrando os totais。
我搜索并没有找到我尝试如下的任何答案:
@foreach (var item in agrupar)
{
<tbody>
<tr style="border:none !important">
@if (ViewBag.bImagemProduto == true)
{
if (!String.IsNullOrEmpty(item.xCaminhoImgProduto))
{
<th style="width:5% !important ; text-align:center"><img src="@item.xCaminhoImgProduto" alt="img" width="50" height="50"></th>
}
else
{
<th style="width:5% !important ; text-align:center"></th>
}
}
@if (ViewBag.bDescricaoProduto)
{
<th style="width:30% !important;word-wrap: normal;word-break: break-all;"><div style="word-wrap: normal;word-break: break-word;font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif !important;font-weight: 600 !important;font-size: 12px !important;">@item.xNome</div></th>
}
@if (ViewBag.bUnProduto)
{
<th style="font-size: 13px !important; width:5% !important ; text-align:center !important">@item.xUnidade</th>
}
</tr>
</tbody>
<span style="margin-bottom: 1px !important; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif !important ; font-size: 18px !important ; color: #4CAF50 !important ; font-weight: 700 !important ; float: right !important">
Total por categoria:
<span style="color: #212121 !important">
@{ var totalPorCategoria = Model.itens.Where(c => c.idCategoria == item.idCategoria).Sum(s => s.vSubTotal).ToString("N2"); }
@totalPorCategoria
</span>
</span>
}