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
Post a Comment