I have some razor code like:
foreach (var item in projectGroup) {
<tr>
...
<td>
<label id="@( "fieldapprovallabel" + @item.InvoiceLineId)">@item.FieldUserName</label>
@if(item.FieldApproved != null) {
<img src="../../Content/Images/stock_lock.gif" alt="locked" class="lockicon" />
}
</td>
...
}
So basically the lock image is only visible based on a condition. I understand it is not good to have logic like this in the view. Can anyone suggest a better way of doing this?
I don’t believe there is anything wrong with simple boolean logic or null checking in the view.
The only alternative would be to hide it all in some helper class that would return the html (or an empty string), which I think adds unnecessary complexity in a simple case like this.