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
Olivier Muhring
NA
150
10.1k
ASP .NET Core - posting a filled in model back
Dec 30 2020 8:26 AM
I'm working on a web application that basically allows you to manage jury duty within a sports federation. One of the pages serves to assign people to a number of predefined "duties" within predefined panels. The page shows the side of the available panels (3 on a row). You can then select the panel you want to modify.
Technically, within the page, I load a partial view for each available panel. When you select a panel to edit, the page is reloaded and the selected panel is reloaded in an editable partial view.
edit.cshtml
@model Models.Database.Models.PanelModel
<div
class
=
"border-right"
>
<form asp-action=
"SavePanel"
method=
"post"
>
<div asp-validation-summary=
"ModelOnly"
class
=
"text-danger"
></div>
<input type=
"hidden"
id=
"currentPanel"
name=
"currentPanel"
asp-
for
=
"@Model.PanelName"
/>
<input type=
"hidden"
id=
"wedstrijdSessie"
name=
"wedstrijdSessie"
asp-
for
=
"@Model.WedstrijdSessie"
/>
<input type=
"hidden"
id=
"currentMembers"
name=
"currentMembers"
asp-
for
=
"@Model.PanelComposition"
/>
<div
class
=
"form-group"
>
<div
class
=
"row"
>
<div
class
=
"col-md-6 text-center d-flex align-items-center justify-content-center"
>
<input type=
"submit"
value=
"Edit"
class
=
"btn btn-outline-info"
/>
</div>
<div
class
=
"col-md-6 text-center d-flex align-items-center justify-content-center"
>
<input type=
"button"
value=
"Overview"
class
=
"btn btn-outline-info"
onclick=
"location.href = '@Url.Action("
Index
", "
JuryOpsteller
", new { id = Model.WedstrijdSessie })'"
/>
</div>
</div>
</div>
<h3>@Model.PanelName</h3>
<div
class
=
"container-fluid mb-3"
>
<div
class
=
"container bg-light"
>
@
foreach
(var panel
in
Model.PanelComposition)
{
<hr style=
"border-style: dotted;"
/>
<div
class
=
"row formgroup align-items-center"
>
<div
class
=
"col-4"
>
<label
class
=
"control-label"
><p
class
=
"font-weight-bold"
>@panel.Functie:</p></label>
</div>
<div
class
=
"col-8"
>
<select asp-
for
=
"@panel.FK_Jury"
asp-items=
"Model.JuryMembers"
class
=
"form-control text-center d-flex align-items-center justify-content-center"
id =
"currentSelectedJuryMemmber"
name=
"currentSelectedJuryMemmber"
value=
"@panel.JuryName"
></select>
<span asp-validation-
for
=
"@panel.JuryName"
class
=
"text-danger"
></span>
</div>
</div>
}
</div>
</div>
</form>
</div>
_EditPanelView.cshtml
@model Models.Database.Models.PanelModel
<div
class
=
"border-right"
>
<form asp-action=
"SavePanel"
method=
"post"
>
<div asp-validation-summary=
"ModelOnly"
class
=
"text-danger"
></div>
<input type=
"hidden"
id=
"currentPanel"
name=
"currentPanel"
asp-
for
=
"@Model.PanelName"
/>
<input type=
"hidden"
id=
"wedstrijdSessie"
name=
"wedstrijdSessie"
asp-
for
=
"@Model.WedstrijdSessie"
/>
<input type=
"hidden"
id=
"currentMembers"
name=
"currentMembers"
asp-
for
=
"@Model.PanelComposition"
/>
<div
class
=
"form-group"
>
<div
class
=
"row"
>
<div
class
=
"col-md-6 text-center d-flex align-items-center justify-content-center"
>
<input type=
"submit"
value=
"Edit"
class
=
"btn btn-outline-info"
/>
</div>
<div
class
=
"col-md-6 text-center d-flex align-items-center justify-content-center"
>
<input type=
"button"
value=
"Overview"
class
=
"btn btn-outline-info"
onclick=
"location.href = '@Url.Action("
Index
", "
JuryOpsteller
", new { id = Model.WedstrijdSessie })'"
/>
</div>
</div>
</div>
<h3>@Model.PanelName</h3>
<div
class
=
"container-fluid mb-3"
>
<div
class
=
"container bg-light"
>
@
foreach
(var panel
in
Model.PanelComposition)
{
<hr style=
"border-style: dotted;"
/>
<div
class
=
"row formgroup align-items-center"
>
<div
class
=
"col-4"
>
<label
class
=
"control-label"
><p
class
=
"font-weight-bold"
>@panel.Functie:</p></label>
</div>
<div
class
=
"col-8"
>
<select asp-
for
=
"@panel.FK_Jury"
asp-items=
"Model.JuryMembers"
class
=
"form-control text-center d-flex align-items-center justify-content-center"
id =
"currentSelectedJuryMemmber"
name=
"currentSelectedJuryMemmber"
value=
"@panel.JuryName"
></select>
<span asp-validation-
for
=
"@panel.JuryName"
class
=
"text-danger"
></span>
</div>
</div>
}
</div>
</div>
</form>
</div>
_EditPanelView.cshtml
displays a combo box for each duty, which contains a listing of the available jury members. In the end, we can click on "Edit" which then changes the listing. But no matter what I do the PanelComposition property always comes back as null, while it's supposed to contain the Jurymember data. How do I fix this?
Reply
Answers (
6
)
how to make modal popup in C#
how to count a <i></i> tag