Skip to content
Loading
asp.net core razor show div if model has data  
  •             @foreach (var item1 in Model.HazIds)  
  •             {  
  •                 class="row no-gutters">  
  •                     class="col-3">  
  •                         class="form-control" style="font-size:12px;">@Html.DisplayFor(modelItem => item1.HazClass)  
  •                       
  •                     class="col-3">  
  •                         class="form-control" style="font-size:12px;">@Html.DisplayFor(modelItem => item1.HazDetails)  
  •                       
  •                     class="col-3">  
  •                         class="form-control" style="font-size:12px;">@Html.DisplayFor(modelItem => item1.HazPMClass)  
  •                       
  •                     class="col-3">  
  •                         class="form-control" style="font-size:12px;">@Html.DisplayFor(modelItem => item1.HazPMDetails)  
  •                       
  •                   
  •             }  
  •           
  •     }  
  •   
    but is not giving then results expected. If I use !=null it shows the div content (labels) even when model has no data; if I use ==null it does not show anything even if the model has data
     
    HazIds is an IList model containing int and strings

    3 Replies

    Know the answer? Post it — somebody with the same question will find it here.