Only show when value is not empty
This example uses a text field (E222) that should only be visible on the display when it has a value (not empty) for the given record.
@if (!@Model.E222.IsEmpty){
<tr>
<td>@Model.E222.Label</td>
<td>
<span>@Model.E222</span>
</td>
</tr>
}
Extra explanation on the code:
-
@if indicates that the next section (until '}') only applies if the condition is true.
-
Use the '!' in front of the @Model, to say that it is NOT empty
The code placed in a table:
<table class="table">
<thead>
</thead>
<tbody>
@if (!@Model.E222.IsEmpty){
<tr>
<td>@Model.E222.Label</td>
<td>
<span>@Model.E222</span>
</td>
</tr>
}
</tbody>
</table>