ASP.NET MVC calculating Shipping total

前端 未结 2 2051
日久生厌
日久生厌 2021-01-29 09:15

How do I calculate the shipping total in razor html. Shipping charges are $3.99 for the first item and $.99 for each additional item.

 @{
     double itemTotal          


        
2条回答
  •  悲&欢浪女
    2021-01-29 09:50

    You can add a simple condition and addition to your loop:

    @{
        double itemTotal = 0;
        double subTotal = 0;
        int totalQty = 0;
        double discount = 0.8;
        double shippingBase = 3.99;
        double shippingItem = 0.99;
        double totalShipping = 0; //used to calculate the cumulative shipping total
    }
    
    @foreach (var item in Model)
    {
    
        double price = (double)item.price / 100 * discount;
        itemTotal = @item.qty * price;
        subTotal += itemTotal;
        totalQty += @item.qty;
        totalShipping += ((totalShipping >= shippingBase) ? shippingItem : shippingBase);
    }
    

提交回复
热议问题