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
592
1.9k
145.3k
asp.net core razor show div if model has data
Nov 24 2020 11:51 AM
I want to show a div if the asociated model has data after OnPost. What I tried is
@
if
(Model.HazIds !=
null
)
{
<div id=
"HazardIdentification"
>
<p
class
=
"text-lg-left text-primary pl-1 mt-1 mb-1"
style=
"font-size:24px"
>Hazard Identification</p>
<div
class
=
"row no-gutters"
>
<div
class
=
"col-3"
>
<label
for
=
"NameGT"
class
=
"form-control badge-primary"
>Hazard Class</label>
</div>
<div
class
=
"col-3"
>
<label
for
=
"EquipmentUsed"
class
=
"form-control badge-primary"
>Hazard Detail</label>
</div>
<div
class
=
"col-3"
>
<label
for
=
"Oxygen"
class
=
"form-control badge-primary"
>Hazard Protective Measure Class</label>
</div>
<div
class
=
"col-3"
>
<label
for
=
"LEL"
class
=
"form-control badge-primary"
>Hazard Protective Measure Detail</label>
</div>
</div>
@
foreach
(var item1
in
Model.HazIds)
{
<div
class
=
"row no-gutters"
>
<div
class
=
"col-3"
>
<span
class
=
"form-control"
style=
"font-size:12px;"
>@Html.DisplayFor(modelItem => item1.HazClass)</span>
</div>
<div
class
=
"col-3"
>
<span
class
=
"form-control"
style=
"font-size:12px;"
>@Html.DisplayFor(modelItem => item1.HazDetails)</span>
</div>
<div
class
=
"col-3"
>
<span
class
=
"form-control"
style=
"font-size:12px;"
>@Html.DisplayFor(modelItem => item1.HazPMClass)</span>
</div>
<div
class
=
"col-3"
>
<span
class
=
"form-control"
style=
"font-size:12px;"
>@Html.DisplayFor(modelItem => item1.HazPMDetails)</span>
</div>
</div>
}
</div>
}
but is not giving then results expected. If I use !=null it shows the div content (labels) even when model has no data; if I use ==null it does not show anything even if the model has data
HazIds is an IList model containing int and strings
Reply
Answers (
3
)
asp.net core Razor pages @Html.DropDownListFor selected value as Input
Is it possible to package the website link running on mobile devices ?