在我的應用程式中,有一個表格顯示了我從控制器傳遞的資料。
在最后一列中,我想通過乘以數量和單位金額資料來顯示總金額。
我可以得到幫助來做這個方法嗎?提前致謝。
這是代碼
<div class="row">
<div class="col-12 table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>Requesting Item</th>
<th>Required Qty</th>
<th>Unit Amount</th>
<th>Total Amount</th>
</tr>
</thead>
<tbody>
@{int RowNo = 0;}
@for (int i = 0; i < Model.First().PurchaseOrderItems.Count; i )
{
<tr>
<td>@{RowNo ;} @RowNo</td>
<td>@Html.DisplayFor(Model => Model.First().PurchaseOrderItems[i].Item_Description)</td>
<td>@Html.DisplayFor(Model => Model.First().PurchaseOrderItems[i].Qty)</td>
<td>[email protected](Model => Model.First().PurchaseOrderItems[i].UnitAmount)</td>
<td></td>
</tr>
}
</tbody>
</table>
</div>
</div>
uj5u.com熱心網友回復:
我會在您的控制器中處理計算,然后將該計算的輸出設定為模型上的新屬性(如TotalAmount或PurchasedOrderTotalAmount。這將使在您的模板中呈現更容易。
<div class="row">
<div class="col-12 table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>Requesting Item</th>
<th>Required Qty</th>
<th>Unit Amount</th>
<th>Total Amount</th>
</tr>
</thead>
<tbody>
@{int RowNo = 0;}
@for (int i = 0; i < Model.First().PurchaseOrderItems.Count; i )
{
<tr>
<td>@{RowNo ;} @RowNo</td>
<td>@Html.DisplayFor(Model => Model.First().PurchaseOrderItems[i].Item_Description)</td>
<td>@Html.DisplayFor(Model => Model.First().PurchaseOrderItems[i].Qty)</td>
<td>[email protected](Model => Model.First().PurchaseOrderItems[i].UnitAmount)</td>
<td></td>
</tr>
}
<tr>
<td colspan="4">Total Amount:</td>
<td>[email protected](Model => Model.First().PurchasedOrderTotalAmount)</td>
</tr>
</tbody>
</table>
</div>
</div>
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/371372.html
