Marius Vasile

Marius Vasile

  • 594
  • 1.9k
  • 145.6k

asp.net core show sublist if data exists

Feb 5 2021 8:54 AM
I am trying to display a sublist on a button click if data exists, if not to redirect to another page. What I did
 
View page
 
  1. @foreach (var a in Model.WOForms)  
  2.         {  
  3.             <div class="row no-gutters mt-2 ml-2">  
  4.                 <div class="col-md-1">  
  5.                     @if (Model.WOS == true)  
  6.                     {  
  7.                         <input type="submit" class="form-control btn-link" asp-page-handler="WOForm" asp-route-id="@a.WONumber" value="@Html.DisplayFor(modelItem => a.WONumber)" />  
  8.                     }  
  9.                     @if (Model.WOS == false)  
  10.                     {  
  11.                         <button type="button" class="col-sm-12 btn btn-link font-weight-bold" style="border-color:firebrick; background-color:lightgray; color:firebrick" data-toggle="collapse" data-target="#Subsequent" aria-expanded="false" aria-controls="Subsequent">@Html.DisplayFor(modelItem => a.WONumber)</button>  
  12.                     }  
  13.                 </div>  
  14.                 <div class="col-md-2 ml-1">  
  15.                     <span class="form-control">@Html.DisplayFor(modelItem => a.AssetName)</span>  
  16.                 </div>  
  17.                 <div class="col-md-2 ml-1">  
  18.                     <span class="form-control">@Html.DisplayFor(modelItem => a.EquipmentName)</span>  
  19.                 </div>  
  20.                 <div class="col-md-2 ml-1">  
  21.                     <span class="form-control">@Html.DisplayFor(modelItem => a.ComponentName)</span>  
  22.                 </div>  
  23.                 <div class="col-md-3 ml-1">  
  24.                     <span class="form-control">@Html.DisplayFor(modelItem => a.Deficiency)</span>  
  25.                 </div>  
  26.                 <div class="col-md-1 ml-1">  
  27.                     <span class="form-control">@Html.DisplayFor(modelItem => a.WOStatus)</span>  
  28.                 </div>  
  29.             </div>  
  30.             <div id="Subsequent" class="collapse">  
  31.                 <div class="col-sm-12 row no-gutters pl-5">  
  32.                     @foreach (var b in Model.WOSubsequents)  
  33.                     {  
  34.                         <div class="col-md-1 ml-1">  
  35.                             <input type="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)" />  
  36.                         </div>  
  37.                         <div class="col-md-2 ml-1">  
  38.                             <span class="form-control">@Html.DisplayFor(modelItem => a.AssetName)</span>  
  39.                         </div>  
  40.                         <div class="col-md-2 ml-1">  
  41.                             <span class="form-control">@Html.DisplayFor(modelItem => a.EquipmentName)</span>  
  42.                         </div>  
  43.                         <div class="col-md-2 ml-1">  
  44.                             <span class="form-control">@Html.DisplayFor(modelItem => a.ComponentName)</span>  
  45.                         </div>  
  46.                         <div class="col-md-3 ml-1">  
  47.                             <span class="form-control">@Html.DisplayFor(modelItem => a.Deficiency)</span>  
  48.                         </div>  
  49.                         <div class="col-md-1 ml-1">  
  50.                             <span class="form-control">@Html.DisplayFor(modelItem => a.WOStatus)</span>  
  51.                         </div>  
  52.                     }  
  53.   
  54.                 </div>  
  55.             </div>  
  56.         }  
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
 
 

Answers (8)