我是 ASP.NET 的新手,仍然通過自學來學習。因此,在視圖上的 ASP.NET MVC 應用程式中,有一些表可以加載資料并顯示給用戶。在這里,我想通過列資料Total顯示 Amount Cell 末尾的值。資料型別是。我正在努力做到這一點,因為我仍然不擅長 javascript。那么我可以在這里得到幫助嗎?謝謝。sumInvoice Amountdecimal
這是我的桌子
<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>
uj5u.com熱心網友回復:
你可以簡單地使用@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>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/445779.html
