TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
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
@
foreach
(var a
in
Model.WOForms)
{
<div
class
=
"row no-gutters mt-2 ml-2"
>
<div
class
=
"col-md-1"
>
@
if
(Model.WOS ==
true
)
{
<input type=
"submit"
class
=
"form-control btn-link"
asp-page-handler=
"WOForm"
asp-route-id=
"@a.WONumber"
value=
"@Html.DisplayFor(modelItem => a.WONumber)"
/>
}
@
if
(Model.WOS ==
false
)
{
<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>
}
</div>
<div
class
=
"col-md-2 ml-1"
>
<span
class
=
"form-control"
>@Html.DisplayFor(modelItem => a.AssetName)</span>
</div>
<div
class
=
"col-md-2 ml-1"
>
<span
class
=
"form-control"
>@Html.DisplayFor(modelItem => a.EquipmentName)</span>
</div>
<div
class
=
"col-md-2 ml-1"
>
<span
class
=
"form-control"
>@Html.DisplayFor(modelItem => a.ComponentName)</span>
</div>
<div
class
=
"col-md-3 ml-1"
>
<span
class
=
"form-control"
>@Html.DisplayFor(modelItem => a.Deficiency)</span>
</div>
<div
class
=
"col-md-1 ml-1"
>
<span
class
=
"form-control"
>@Html.DisplayFor(modelItem => a.WOStatus)</span>
</div>
</div>
<div id=
"Subsequent"
class
=
"collapse"
>
<div
class
=
"col-sm-12 row no-gutters pl-5"
>
@
foreach
(var b
in
Model.WOSubsequents)
{
<div
class
=
"col-md-1 ml-1"
>
<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)"
/>
</div>
<div
class
=
"col-md-2 ml-1"
>
<span
class
=
"form-control"
>@Html.DisplayFor(modelItem => a.AssetName)</span>
</div>
<div
class
=
"col-md-2 ml-1"
>
<span
class
=
"form-control"
>@Html.DisplayFor(modelItem => a.EquipmentName)</span>
</div>
<div
class
=
"col-md-2 ml-1"
>
<span
class
=
"form-control"
>@Html.DisplayFor(modelItem => a.ComponentName)</span>
</div>
<div
class
=
"col-md-3 ml-1"
>
<span
class
=
"form-control"
>@Html.DisplayFor(modelItem => a.Deficiency)</span>
</div>
<div
class
=
"col-md-1 ml-1"
>
<span
class
=
"form-control"
>@Html.DisplayFor(modelItem => a.WOStatus)</span>
</div>
}
</div>
</div>
}
cshtml
WOForms = await (from a
in
_context.WOMains.Where(a => a.OrgID == orgid)
join b
in
_context.WOInitiators on a.WOMainID equals b.WOMainID into Temp1
from c
in
Temp1
select
new
WOForm
{
WONumber = a.WONumber,
//other fields
}).ToListAsync();
foreach
(var i
in
WOForms)
{
WOSubsequents = await _context.WOSubsequents.Where(s => s.WONumber == i.WONumber).OrderBy(s => s.WONumberS).ToListAsync();
if
(WOSubsequents.Count() > 0)
{
WOS =
false
;
}
else
{
WOS =
true
;
}
}
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
Reply
Answers (
8
)
how to correct the error
How to Unzip Data On Client Side ?