[RESOLVED]bootstrap glyphicons in a ternary operation

I want to show two different glyphicons depending on IsCompleted.

It doesn’t like the span there.

Some pointers would be appreciated.

@(records.ElementAt(r).IsCompleted ? <span class="glyphicon glyphicon-cloud-upload"></span> : <span class="glyphicon glyphicon-cloud-download"></span>)

The @ sign means C# code mode, so change it to this:

@(records.ElementAt(r).IsCompleted ? "<span class=’glyphicon glyphicon-cloud-upload’></span>" : "<span class=’glyphicon glyphicon-cloud-download’></span>")

In the first version below VS is complaining about missing ‘:’ and missing ‘;’ at the end

In the second version VS has nothing to complain about but it does not get rendered.

@(records.ElementAt(r).IsCompleted ? "<span class="glyphicon glyphicon-cloud-upload"></span>" : "<span class="glyphicon glyphicon-cloud-download"></span>"

@(records.ElementAt(r).IsCompleted ? "<span class=’glyphicon glyphicon-cloud-upload’></span>" : "<span class=’glyphicon glyphicon-cloud-download’></span>")

You can always do this:

@if(records.ElementAt(r).IsCompleted)
{
<span class="glyphicon glyphicon-cloud-upload"></span>
}
else
{
<span class="glyphicon glyphicon-cloud-download"></span>
}

Yes, that works.

Wonder why that ternary operator is so sensitive.

Thanks.

Leave a Reply