Reputation: 21
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:
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
Reputation: 1067
Try it like this...
<p>
@{
decimal totalPrice = ((decimal)ViewBag.InvHardwareTotalPrice) + ((decimal)ViewBag.InvSoftwareTotalPrice) + ((decimal)ViewBag.InvFurnitureTotalPrice);
@totalPrice.ToString("C2")
}
</p>
Upvotes: 1