c# - How do I conditionally output HTML with Razor syntax? -


this question has answer here:

what i'm trying simple:

<td class="bold-and-caps">@{if (++i == 1) { subsec.title } else { string.empty } } </td> 

except i'm getting

"only assignment, call, increment, decrement, await , new object expressions can used statement"

on subsec.title , string.empty.

how supposed write "if condition, output x" type statements in razor?

you can use ternary operator like:

<td class="bold-and-caps">@( (++i == 1) ? subsec.title : string.empty)</td> 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -