I have a foreach and several conditions within. Basically, I want to show an a link if PTWNoS is null and a span if PTWNoS is not null. The problem is I have a group and I don't know how to build the condition, similar with the one in the second foreach
C#
@foreach (var group in Model.PTWContents.GroupBy(s => new { s.PTWMain.PTWId, s.PTWMain.PTWNo }).OrderByDescending(s => s.Key.PTWNo))
{
@if (User.IsInRole("PTWIsoCert"))
{
@Html.DisplayFor(modelItem => group.Key.PTWNo)
}
else if (User.IsInRole("PTWIsoCert"))
{
@Html.DisplayFor(modelItem => group.Key.PTWNo)
}
else
{
@Html.DisplayFor(modelItem => group.Key.PTWNo)
}
@foreach (var item in group.OrderBy(s => s.StartDate))
{
@if (item.PTWSubsequent != null && item.PTWSubsequent.PTWNoS != 0)
{
@if (User.IsInRole("PTWIsoCert"))
{
@Html.DisplayFor(model => item.PTWMain.PTWNo) - @Html.DisplayFor(model => item.PTWSubsequent.PTWNoS)
}
else
{
@Html.DisplayFor(modelItem => item.PTWMain.PTWNo) - @Html.DisplayFor(modelItem => item.PTWSubsequent.PTWNoS)
}
}
else
{
No Subsequent
}
@Html.DisplayFor(model => item.PTWType)
@Html.DisplayFor(model => item.WorkScope)
@Html.DisplayFor(model => item.StartDate)
@Html.DisplayFor(model => item.EndDate)
@Html.DisplayFor(model => item.PTWStatus)
}
}

Marius VasileRank #785 · 2.9K reputationPosted Sep 4, 2021, 7:48 AM EDT
Sachin SinghRank #66 · 26.2K reputationPosted Sep 4, 2021, 5:39 PM EDT