I have an enum as follows:
enum ProgressStatus{
Approved,
Unapproved,
InProcess
}
I have an Project
object that use this class. Based on the enum values I need to show their values as Green, Yellow or Blue in while styling.
<ol class="breadcrumb">
@if (Model.ProgressStatus == ProgressStatus.Approved)
{
<li style="color:red;"><label>Vaziyet Planı</label></li>
}
</ol>
This is how i try to do it but it get cumbersome and clumsy.
What is the correct way to get this done?
with your enum, you can use a short switch to set the color:
@{
string color;
switch(Model.ProgressStatus)
{
case ProgressStatus.Approved : color = "green"; break;
case ProgressStatus.Unapproved : color = "yellow"; break;
//...
}
}
then you only need the one element
<li style="color:@color;"><label>Vaziyet Planı</label></li>
This is just a different take on Stijn's answer really. I like his better.
Put this in your view:
@{
var labelColours = new Dictionary<ProgressStatus, string>()
{
{ ProgressStatus.Approved, "green" },
{ ProgressStatus.Unapproved, "yellow" },
{ ProgressStatus.InProcess, "blue" }
};
}
Then use this in your label:
<li style="color: @labelColours[Model.ProgressStatus];">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With