mardi 1 janvier 2019

convert if else condition to ternary operator in asp.net mvc [duplicate]

This question already has an answer here:

i want to shorten my code by converting if condition to ternary operator in my razor view. i have one flagged enumerator on the basis of the current Status value in table and value assigned in the enumerator i have to change my button icon color if it is matching icon should be red or it is default.

[Flags]
public enum EnumHkStatus
{
    None = 0,
    Repair = 1,
    Cleaning = 2,
    InventoryCheck = 3,
    Occupied = 4 
};

@if (item.Status & EnumHkStatus.Repair = 1)

{
   <button type="button" class="btn btn-default"><i class="fas fa-key" style="color:red;"></i></button>
}

else

{
   <button type="button" class="btn btn-default"><i class="fas fa-key"></i></button>
}

i have above razor view code if current status and EnumHkStatus is = 1
then the button font-awesome icon should be red or it is normal color i want to convert this to single line with ternary operator how to achieve that

Aucun commentaire:

Enregistrer un commentaire