Null attribute check in @Html.Displaynamefor

Asked

Viewed 79 times

2

I need to check if the attribute of a class is null. If it is null, I would like to hide its label. Below is an example of how it is being displayed today:

inserir a descrição da imagem aqui

The attribute Dating null came, so it would not display its label. Below the HTML code structure:

<div class="label label-primary">
     @Html.DisplayNameFor(model => model.DataSolucao)
</div>
<div class="display-field">
     @Html.DisplayFor(model => model.DataSolucao)
 </div>

 <div class="label label-primary">
     @Html.DisplayNameFor(model => model.DataFinalizacao)
 </div>
 <div class="display-field">
     @Html.DisplayFor(model => model.DataFinalizacao)
 </div>

How should I check ?

1 answer

3


It’s not much of a secret:

@if (Model.DataFinalizacao != null) 
{
    <div class="label label-primary">
         @Html.DisplayNameFor(model => model.DataFinalizacao)
     </div>
     <div class="display-field">
         @Html.DisplayFor(model => model.DataFinalizacao)
     </div>
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.