Table 单元格值的总和并在底端显示总计

SUM of the Table cell values and show total on bottom end

我是 ASP.NET 的新手,并且仍在通过自学来学习。因此,在我的 ASP.NET MVC 应用程序视图中,有一些表可以加载数据并显示给用户。在这里,我想通过 sum Invoice Amount 列数据在 Amount 单元格末尾显示 Total 值。数据类型为 decimal。我正在努力去做,因为我仍然不擅长 javascript。那么我可以在这里得到帮助吗?谢谢。

这是我的Table

 <table class="table">
   <tr>
     <th> Inoice Number </th>
     <th> Invoice Amount </th>
     <th> Attachment </th>
     <th></th>
   </tr> @foreach (var item in Model.PaybillInvoiceDetailsList) { <tr>
     <td> @Html.DisplayFor(modelItem => item.Invoice_No) </td>
     <td> @Html.DisplayFor(modelItem => item.Invoice_Amount) </td>
     <td>
       <a href="@Url.Action(" RetrieveImagePbI", new { id=item.Id })" target="_blank" rel="noreferrer noopener">
         <img width="100" height="100" border="0" class="m1-1" align="center" src="@Url.Action(" RetrieveImagePbI", new { id=item.Id })" />
       </a>
     </td>
   </tr> }
 </table>

您可以简单地使用 @Model.PaybillInvoiceDetailsList.Sum(i => i. Invoice_Amount).ToString("0.##")

全部修改即可

 <table class="table">
   <tr>
     <th> Inoice Number </th>
     <th> Invoice Amount </th>
     <th> Attachment </th>
     <th></th>
   </tr>
   @foreach (var item in Model.PaybillInvoiceDetailsList) { <tr>
     <td> @Html.DisplayFor(modelItem => item.Invoice_No) </td>
     <td> @Html.DisplayFor(modelItem => item.Invoice_Amount) </td>
     <td>
       <a href="@Url.Action(" RetrieveImagePbI", new { id=item.Id })" target="_blank" rel="noreferrer noopener">
         <img width="100" height="100" border="0" class="m1-1" align="center" src="@Url.Action(" RetrieveImagePbI", new { id=item.Id })" />
       </a>
     </td>
   </tr> }
   <tr>
    <td colspan"3">Total</td>
    <td>@Model.PaybillInvoiceDetailsList.Sum(i => i.Invoice_Amount).ToString("0.##")</td>
   </tr>
 </table>