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

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


This should work:

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


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