This question already has an answer here:
Not having much luck, I have the following if/else statement in Razor which works perfectly
<small>
@if(deletedView){
@:Deleted
}
else {
@:Created
} by
</small>
I am trying to do something like this:
<small>
@(deletedView) ? @:Deleted : @:Created by
</small>
But that fails miserably. What is the proper syntax?
You need to put the entire ternary expression in parenthesis. Unfortunately that means you can't use "@:", but you could do something like this:
Razor currently supports a subset of C# expressions without using @() and unfortunately, ternary operators are not part of that set.