Olivier Muhring

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
  1. @model Models.Database.Models.PanelModel  
  2.   
  3. <div class="border-right">  
  4.     <form asp-action="SavePanel" method="post">  
  5.         <div asp-validation-summary="ModelOnly" class="text-danger"></div>  
  6.         <input type="hidden" id="currentPanel" name="currentPanel" asp-for="@Model.PanelName" />  
  7.         <input type="hidden" id="wedstrijdSessie" name="wedstrijdSessie" asp-for="@Model.WedstrijdSessie" />  
  8.         <input type="hidden" id="currentMembers" name="currentMembers" asp-for="@Model.PanelComposition" />  
  9.   
  10.         <div class="form-group">  
  11.             <div class="row">  
  12.                 <div class="col-md-6 text-center d-flex align-items-center justify-content-center">  
  13.                     <input type="submit" value="Edit" class="btn btn-outline-info"/>  
  14.                 </div>  
  15.                 <div class="col-md-6 text-center d-flex align-items-center justify-content-center">  
  16.                     <input type="button" value="Overview" class="btn btn-outline-info" onclick= "location.href = '@Url.Action("Index", "JuryOpsteller", new { id = Model.WedstrijdSessie })'"/>  
  17.                 </div>  
  18.             </div>  
  19.         </div>  
  20.   
  21.         <h3>@Model.PanelName</h3>  
  22.   
  23.         <div class="container-fluid mb-3">  
  24.             <div class="container bg-light">  
  25.                 @foreach (var panel in Model.PanelComposition)  
  26.                 {  
  27.                     <hr style="border-style: dotted;"/>  
  28.   
  29.                     <div class="row formgroup align-items-center">  
  30.                         <div class="col-4">  
  31.                             <label class="control-label"><p class="font-weight-bold">@panel.Functie:</p></label>  
  32.                         </div>  
  33.                         <div class="col-8">  
  34.                             <select asp-for="@panel.FK_Jury"  
  35.                                     asp-items="Model.JuryMembers"  
  36.                                     class="form-control text-center d-flex align-items-center justify-content-center"  
  37.                                     id ="currentSelectedJuryMemmber"  
  38.                                     name="currentSelectedJuryMemmber"  
  39.                                     value="@panel.JuryName"></select>  
  40.                             <span asp-validation-for="@panel.JuryName" class="text-danger"></span>  
  41.                         </div>  
  42.                     </div>  
  43.                 }  
  44.             </div>  
  45.         </div>  
  46.     </form>  
  47. </div>  
_EditPanelView.cshtml
  1. @model Models.Database.Models.PanelModel  
  2.   
  3. <div class="border-right">  
  4.     <form asp-action="SavePanel" method="post">  
  5.         <div asp-validation-summary="ModelOnly" class="text-danger"></div>  
  6.         <input type="hidden" id="currentPanel" name="currentPanel" asp-for="@Model.PanelName" />  
  7.         <input type="hidden" id="wedstrijdSessie" name="wedstrijdSessie" asp-for="@Model.WedstrijdSessie" />  
  8.         <input type="hidden" id="currentMembers" name="currentMembers" asp-for="@Model.PanelComposition" />  
  9.   
  10.         <div class="form-group">  
  11.             <div class="row">  
  12.                 <div class="col-md-6 text-center d-flex align-items-center justify-content-center">  
  13.                     <input type="submit" value="Edit" class="btn btn-outline-info"/>  
  14.                 </div>  
  15.                 <div class="col-md-6 text-center d-flex align-items-center justify-content-center">  
  16.                     <input type="button" value="Overview" class="btn btn-outline-info" onclick= "location.href = '@Url.Action("Index", "JuryOpsteller", new { id = Model.WedstrijdSessie })'"/>  
  17.                 </div>  
  18.             </div>  
  19.         </div>  
  20.   
  21.         <h3>@Model.PanelName</h3>  
  22.   
  23.         <div class="container-fluid mb-3">  
  24.             <div class="container bg-light">  
  25.                 @foreach (var panel in Model.PanelComposition)  
  26.                 {  
  27.                     <hr style="border-style: dotted;"/>  
  28.   
  29.                     <div class="row formgroup align-items-center">  
  30.                         <div class="col-4">  
  31.                             <label class="control-label"><p class="font-weight-bold">@panel.Functie:</p></label>  
  32.                         </div>  
  33.                         <div class="col-8">  
  34.                             <select asp-for="@panel.FK_Jury"  
  35.                                     asp-items="Model.JuryMembers"  
  36.                                     class="form-control text-center d-flex align-items-center justify-content-center"  
  37.                                     id ="currentSelectedJuryMemmber"  
  38.                                     name="currentSelectedJuryMemmber"  
  39.                                     value="@panel.JuryName"></select>  
  40.                             <span asp-validation-for="@panel.JuryName" class="text-danger"></span>  
  41.                         </div>  
  42.                     </div>  
  43.                 }  
  44.             </div>  
  45.         </div>  
  46.     </form>  
  47. </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?

Answers (6)