簡體   English   中英

如何將兩列相乘並顯示結果

[英]How to multiply two columns and show the result

在我的應用程序中,有一個表格顯示了我從 controller 傳遞的數據。

在最后一列中,我想通過將數量和單位金額數據相乘來顯示總金額。

我可以得到幫助來做這個方法嗎? 提前致謝。

這是代碼

<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>Rs.@Html.DisplayFor(Model => Model.First().PurchaseOrderItems[i].UnitAmount)</td>
            <td></td>
           </tr>
          }
        </tbody>
      </table>
     </div>
</div>

我將在您的 Controller 中處理計算,然后將該計算的 output 設置為 model 上的新屬性(如TotalAmountPurchasedOrderTotalAmount .

<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>Rs.@Html.DisplayFor(Model => Model.First().PurchaseOrderItems[i].UnitAmount)</td>
            <td></td>
           </tr>
          }
         <tr>
          <td colspan="4">Total Amount:</td>
          <td>Rs.@Html.DisplayFor(Model => Model.First().PurchasedOrderTotalAmount)</td>
         </tr>
        </tbody>
      </table>
     </div>
</div>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM