C# 每行都有总计,我只想得到一次
我想总结一下我的账单总额。我只想得到一个总数。 现在我得到了数据库中每一行的数据 实际上,输出是这样的C# 每行都有总计,我只想得到一次,c#,asp.net-mvc,C#,Asp.net Mvc,我想总结一下我的账单总额。我只想得到一个总数。 现在我得到了数据库中每一行的数据 实际上,输出是这样的 Stats Nombre de factures: 2 Grand total des factures 71.97 71.97 <=== the total is coming twice. I will like to get only one grand total Stats 名义制造:2 工厂总计 71.97 71.97(一) } 试
Stats
Nombre de factures: 2
Grand total des factures
71.97
71.97 <=== the total is coming twice. I will like to get only one grand total
Stats
名义制造:2
工厂总计
71.97
71.97(一)
}
试试这个,您不需要检查模型中的每个项目,您已经在做总和了
@model IEnumerable<Tp1WebStore3.Models.Facture>
@{
ViewBag.Title = "Stats";
}
<h2>Stats</h2>
<p>
Nombre de factures: @Model.Count()
</p>
<table>
<tr>
<th>
<p> Grand total des factures</p>
</th>
</tr>
<tr>
<td>
@Model.Sum(i => i.TotalFact)
</td>
</tr>
</table>
@model IEnumerable
@{
ViewBag.Title=“Stats”;
}
统计数据
制造名称:@Model.Count()
工厂总计
@Model.Sum(i=>i.TotalFact)
@model IEnumerable<Tp1WebStore3.Models.Facture>
@{
ViewBag.Title = "Stats";
}
<h2>Stats</h2>
<p>
Nombre de factures: @Model.Count()
</p>
<table>
<tr>
<th>
<p> Grand total des factures</p>
</th>
</tr>
<tr>
<td>
@Model.Sum(i => i.TotalFact)
</td>
</tr>
</table>