Razor color div

I show the list of products in my asp.net MVC 3 firewall. I show the products in the foreach loop inside the div. I want the product to be sold and the color of the div to be red. How to change div background color in razor mode?

+4
source share
1 answer

Shaver Type:

@foreach (Product product in Model.ProductList) { string saleClass = product.IsOnSale ? "onSale" : "regular"; <div class="@saleClass"> @product.Description </div> } 

Styles:

 onSale { background-color: red; } regular { background-color: white; } 

Or in a more direct way:

 @foreach (Product product in Model.ProductList) { string style= product.IsOnSale ? "background-color: red" : "background-color: white"; <div style="@style"> @product.Description </div> } 
+4
source

All Articles