【问题标题】:How to multiply two columns and show the result如何将两列相乘并显示结果
【发布时间】:2022-01-01 16:34:09
【问题描述】:

在我的应用程序中有一个表格显示我从控制器传递的数据。

在最后一列中,我想通过将数量和单位金额数据相乘来显示总金额。

我可以得到帮助来执行此方法吗?提前致谢。

这里是代码

<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>

【问题讨论】:

    标签: javascript html asp.net-mvc asp.net-mvc-4


    【解决方案1】:

    我会在控制器中处理计算,然后将该计算的输出设置为模型上的新属性(如 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多