In my application there is a table that shows the data that I passing from the controller.
Here in the last column I want to show the Total Amount by multiplying the Qty and Unit Amount data.
Can I get a help to do this method? Thanks in advance.
Here is the code
<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>
CodePudding user response:
I would handle the calculation in your Controller and then set the output of that calculation as a new property on your model (like TotalAmount
or PurchasedOrderTotalAmount
. This will make it easier to render in your template.
<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>