Skip to content
Loading
asp.net core show sublist if data exists  
  •                 class="col-md-1 ml-1">  
  •                     class="form-control">@Html.DisplayFor(modelItem => a.WOStatus)  
  •                   
  •               
  •             "Subsequent" class="collapse">  
  •                 class="col-sm-12 row no-gutters pl-5">  
  •                     @foreach (var b in Model.WOSubsequents)  
  •                     {  
  •                         class="col-md-1 ml-1">  
  •                             "submit" class="form-control btn-link" asp-page-handler="WOForm" asp-route-id="@a.WONumber" value="@Html.DisplayFor(modelItem => a.WONumber) - @Html.DisplayFor(modelItem => b.WONumberS)" />  
  •                           
  •                         class="col-md-2 ml-1">  
  •                             class="form-control">@Html.DisplayFor(modelItem => a.AssetName)  
  •                           
  •                         class="col-md-2 ml-1">  
  •                             class="form-control">@Html.DisplayFor(modelItem => a.EquipmentName)  
  •                           
  •                         class="col-md-2 ml-1">  
  •                             class="form-control">@Html.DisplayFor(modelItem => a.ComponentName)  
  •                           
  •                         class="col-md-3 ml-1">  
  •                             class="form-control">@Html.DisplayFor(modelItem => a.Deficiency)  
  •                           
  •                         class="col-md-1 ml-1">  
  •                             class="form-control">@Html.DisplayFor(modelItem => a.WOStatus)  
  •                           
  •                     }  
  •   
  •                   
  •               
  •         }  
  • cshtml
     
    1. WOForms = await (from a in _context.WOMains.Where(a => a.OrgID == orgid)  
    2.                             join b in _context.WOInitiators on a.WOMainID equals b.WOMainID into Temp1  
    3.                             from c in Temp1  
    4.   
    5.                             select new WOForm  
    6.                             {  
    7.                                   
    8.                                 WONumber = a.WONumber,  
    9.                                 //other fields  
    10.   
    11.                             }).ToListAsync();  
    12.   
    13.             foreach(var i in WOForms)  
    14.             {  
    15.                 WOSubsequents = await _context.WOSubsequents.Where(s => s.WONumber == i.WONumber).OrderBy(s => s.WONumberS).ToListAsync();  
    16.                 if (WOSubsequents.Count() > 0)  
    17.                 {  
    18.                     WOS = false;  
    19.                 }  
    20.                 else  
    21.                 {  
    22.                     WOS = true;  
    23.                 }  
    24.             }  
    The result is that either buttons are showing the colapsed div or link to the other page while they should be different because one has subsequent data and the other record doesn't
     
    Screen
     
     

    8 Replies

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