Acadia
Acadia

Reputation: 21

How to add ViewBag numbers which from different Model

I have some ViewBag codes:

<p>@(((decimal)ViewBag.InvHardwareTotalPrice).ToString("C2"))</p>
<p>@(((decimal)ViewBag.InvSoftwareTotalPrice).ToString("C2"))</p>
<p>@(((decimal)ViewBag.InvFurnitureTotalPrice).ToString("C2"))</p>

They shows the price of items in webpage:

enter image description here

I want have a space to add the total number of those 3 numbers, I tried but not working:

<p>@((decimal)ViewBag.InvFurnitureTotalPrice) + @((decimal)ViewBag.InvFurnitureTotalPrice)</p>

Any ideas? Thank you!

Upvotes: 0

Views: 47

Answers (1)

Ozan Gunceler
Ozan Gunceler

Reputation: 1067

Try it like this...

<p>
    @{
        decimal totalPrice = ((decimal)ViewBag.InvHardwareTotalPrice) + ((decimal)ViewBag.InvSoftwareTotalPrice) + ((decimal)ViewBag.InvFurnitureTotalPrice);
        @totalPrice.ToString("C2")
    }
</p>

Upvotes: 1

Related Questions