Null attribute check in @ Html.DisplayNameFor

2

I need to check if the attribute of a class is null. If it is null, I would like to hide your label. Here's an example of how it's being viewed today:

TheDataFinalizacaoattributewasnull,soitwouldnotdisplayitslabel.BelowisthestructureoftheHTMLcode:

<divclass="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?

    
asked by anonymous 13.09.2016 / 19:50

1 answer

3

There is not much 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>
}
    
13.09.2016 / 20:04