Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional Formatting with ASP.NET MVC

I have an ASP.NET MVC app that uses Razor in the views. In my view, I have the following:

<table style="width:100%;">
 ...
</table>

I want to say, if (items.Count == 0), then the background color of the table should be orange. However, if (items.Count > 0), I want the background color of the table to be gray. How do I do this with Razor?

Thank you!

like image 884
JQuery Mobile Avatar asked May 21 '26 09:05

JQuery Mobile


1 Answers

Just to give one more option, you can set color at page begining.

@{
    var color = items.Any() ? "#CCC" : "#FF0";
}

And at your table tag

<table style="color:@color"></table>
like image 151
Thiago Lunardi Avatar answered May 23 '26 04:05

Thiago Lunardi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!