How to use ? : if statements with Razor and inline code blocks

Solution 1:

This should work:

<span class="vote-up@(puzzle.UserVote == VoteType.Up ? "-selected" : "")">Vote Up</span>

Solution 2:

@( condition ? "true" : "false" )

Solution 3:

The key is to encapsulate the expression in parentheses after the @ delimiter. You can make any compound expression work this way.