jwaliszko
jwaliszko

Reputation: 17064

Html rendering using ternary operator in Razor view engine

Razor instruction shown below:

<td@(IsAdmin ? " class=editable name" : "") data-attr="name">it's true</td>

results in:

<td class="editable" data-attr="name" name="">it's true</td>

while I need this:

<td class="editable name" data-attr="name">it's true</td>

How to do it ?

Upvotes: 3

Views: 6681

Answers (2)

Kevin Aenmey
Kevin Aenmey

Reputation: 13419

How about this:

<td @Html.Raw(IsAdmin ? " class=\"editable name\"" : "") data-attr="name">it's true</td>

Upvotes: 9

ryudice
ryudice

Reputation: 37366

Like this: @(IsAdmin ? " class=\"editable name\"" : "")

Upvotes: 1

Related Questions