Marius Vasile

Marius Vasile

  • 590
  • 1.9k
  • 148.6k

asp.net core How do I implement GroupBy twice?

May 16 2021 5:04 AM
The results of my query are displayed in a selection of div as below
 
 
 
 By applying a GroupBy, view below, I managed to hide duplicates in Step No, see in the picture below as well. The questions is, how do I do the same for Activity?
  
  1. @foreach (var group1 in Model.JSAViewList.GroupBy(s => s.StepNo))  
  2.     {  
  3.         <div class="row no-gutters">  
  4.             <div class="col-md-1">  
  5.                 <label class="form-control text-white" style="background-color:mediumorchid">Step No:</label>  
  6.             </div>  
  7.             <div class="col-md-11">  
  8.                 <div class="row no-gutters">  
  9.                     <div class="col-md-3">  
  10.                         <label class="form-control text-white" style="background-color:mediumorchid">Activity:</label>  
  11.                     </div>  
  12.                     <div class="col-md-2">  
  13.                         <label class="form-control text-white" style="background-color:mediumorchid">Hazards:</label>  
  14.                     </div>  
  15.                     <div class="col-md-2">  
  16.                         <label class="form-control text-white" style="background-color:mediumorchid">Controls:</label>  
  17.                     </div>  
  18.                     <div class="col-md-2">  
  19.                         <label class="form-control text-white" style="background-color:mediumorchid">PPEs:</label>  
  20.                     </div>  
  21.                     <div class="col-md-2">  
  22.                         <label class="form-control text-white" style="background-color:mediumorchid">Responsible:</label>  
  23.                     </div>  
  24.                 </div>  
  25.             </div>  
  26.         </div>  
  27.   
  28.         <div class="row no-gutters">  
  29.             <div class="col-md-1">  
  30.                 <span class="form-control">@Html.DisplayFor(model => group1.Key)</span>  
  31.             </div>  
  32.             <div class="col-md-11">  
  33.                 @foreach (var item in group1.OrderBy(s => s.StepNo).ThenBy(s => s.Hazard))  
  34.                 {  
  35.                     <div class="row no-gutters">  
  36.                         <div class="col-md-3">  
  37.                             <span class="form-control">@Html.DisplayFor(modelItem => item.ActivitySec)</span>  
  38.                         </div>  
  39.                         <div class="col-md-2">  
  40.                             <span class="form-control">@Html.DisplayFor(modelItem => item.Hazard)</span>  
  41.                         </div>  
  42.                         <div class="col-md-2">  
  43.                             <span class="form-control">@Html.DisplayFor(modelItem => item.Controls)</span>  
  44.                         </div>  
  45.                         <div class="col-md-2">  
  46.                             <span class="form-control">@Html.DisplayFor(modelItem => item.PPE)</span>  
  47.                         </div>  
  48.                         <div class="col-md-2">  
  49.                             <span class="form-control">@Html.DisplayFor(modelItem => item.Responsible)</span>  
  50.                         </div>  
  51.                     </div>  
  52.                 }  
  53.             </div>  
  54.         </div>  
  55.     }  
 
 
 
 
 
 
 

Answers (2)