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
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);
}