Asp.net 我想将6%的增量添加到查询的返回结果中

Asp.net 我想将6%的增量添加到查询的返回结果中,asp.net,asp.net-mvc,asp.net-mvc-4,Asp.net,Asp.net Mvc,Asp.net Mvc 4,首先让我告诉你,我对asp.net mvc一无所知。。 现在我的问题是,我有上面的查询,它在乘以价格和数量后返回总计。现在我想要的是,我想将价格数量的6%增加到价格数量 最终结果将是价格*数量+价格*数量的6% 我希望你们能理解我的问题你们可以这样做: <td> <strong> Rs @(Model.lstItem.Sum(c => c._product.option != null ? (c._produc

首先让我告诉你,我对asp.net mvc一无所知。。 现在我的问题是,我有上面的查询,它在乘以价格和数量后返回总计。现在我想要的是,我想将价格数量的6%增加到价格数量

最终结果将是价格*数量+价格*数量的6%

我希望你们能理解我的问题

你们可以这样做:

<td>
    <strong>
        Rs @(Model.lstItem.Sum(c => c._product.option != null
                ? (c._product.option.Price * c.Quantity)
                : (c._product.product.Price * c.Quantity))
            - (Model.coupon != null ? (int)Model.coupon.Discount : 0))
    </strong>
</td>
您不应该在视图中保留这些常量。如果您在多个地方进行了这些计算,并且您希望在将来将百分比更改为7%,那么您必须在任何地方进行更改。因此,它应该来自数据库、配置文件或常量类

因此,最简单的方法是在公共文件夹或实用工具文件夹中创建一个名为ApplicationConstants的静态类

那么在你看来,

简单的数学。1.06*价格*数量。
(price * quantity) + (((price * quantity)/100) * 6))
public static class ApplicationConstants
{
     public const int ProfitPercentage = 6;
}
@using YourAppName.Common

<td>
    <strong>
        Rs @( 
             (1 + ApplicationConstants.ProfitPercentage / 100) *
             (Model.lstItem.Sum(c => c._product.option != null
                ? (c._product.option.Price * c.Quantity)
                : (c._product.product.Price * c.Quantity)))
            - (Model.coupon != null ? (int)Model.coupon.Discount : 0))
    </strong>
</td>