Skip to content
Loading
  
  •             "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
     
     
    +1
  • Sachin Singh
    +1
    your output is exactly what you are telling him to do.
    your concern is modelNo 82 has subsequent data but 107 doesn't have ?? if this is the case then your class structure should be

    1. public class womains  
    2. {  
    3.  all its singleton properties,  
    4. public List sqs {get;set;} // where subsequent is a class with its own properties  
    5. }  
    6.   
    now fill each object of  womains class with subsequent list then it will work as expected.
    +1
  • Marius Vasile
    +1
    Why can't I do this with EF? There is no difference in the content, actually si the same class. I have the connection made in 
     
    1. public class WOSubsequent  
    2.     {  
    3.         [Key]  
    4.         [DatabaseGenerated(DatabaseGeneratedOption.Identity)]  
    5.         public string WOSID { get; set; }  
    6.         public int WONumber { get; set; }  
    7.         public int WONumberS{ get; set; }  
    8.     }  
    and also the class WOMain which has all the data including WONumber, so it should work but I guess is sothing with the EF that I do wrong
    +1
  • Marius Vasile
    +1
    My issue, to try to be more clear, is that if there is subsequent the button should activate the collapse and if not it should redirect. Now, either both redirect or both activate collapse. the logic in 
     
    1. foreach(var i in WOForms)  
    2.             {  
    3.                 WOSubsequents = await _context.WOSubsequents.Where(s => s.WONumber == i.WONumber).OrderBy(s => s.WONumberS).ToListAsync();  
    4.                 if (WOSubsequents.Count() > 0)  
    5.                 {  
    6.                     WOS = false;  
    7.                 }  
    8.                 else  
    9.                 {  
    10.                     WOS = true;  
    11.                 }  
    12.             }  
    is not effective 
    +1
  • Marius Vasile
    +1
    This is getting even strange. I have two WONumbers, one is 82 the other is 107. The foreach loop below is getting the same result. What is happening?
     
    1. foreach(var i in WOForms)  
    2.             {  
    3.                 if(i.WONumber < 100)  
    4.                 {  
    5.                     WOS = true;  
    6.                 }  
    7.                 if (i.WONumber > 100)  
    8.                 {  
    9.                     WOS = false;  
    10.                 }  
    11.                   
    12.             }  
    1. class="col-md-1">  
    2.                 @if (Model.WOS == true)  
    3.                 {  
    4.                     class="form-control">TRUE  
    5.                 }  
    6.                 @if (Model.WOS == false)  
    7.                 {  
    8.                     class="form-control">FALSE  
    9.                 }  
    10.             
      
  •  
    +1
  • Marius Vasile
    +1
    Now you're talking, thank you Sachin. What is the oposite of Model.WOSubsequents.Count() > 0 ? How do I write the condition if Count is null?
    +1
  • Sachin Singh
    +1
    1. if( Model.WOSubsequents.Count()==0 ||  Model.WOSubsequents==null)  
    2. {  
    3. // write the logic here.  
    4. }  
    +1
  • Marius Vasile
    +1
    I don't get the result I want. I will try more, your logic looks correct but I do something wrong I don't see yet
    +1