Skip to content
Loading
  
  •                         class="col-8">  
  •                             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">  
  •                             for="@panel.JuryName" class="text-danger">  
  •                           
  •                       
  •                 }  
  •               
  •           
  •       
  •   
  • _EditPanelView.cshtml
    1. @model Models.Database.Models.PanelModel  
    2.   
    3. class="border-right">  
    4.     "SavePanel" method="post">  
    5.         "ModelOnly" class="text-danger">
      
  •         "hidden" id="currentPanel" name="currentPanel" asp-for="@Model.PanelName" />  
  •         "hidden" id="wedstrijdSessie" name="wedstrijdSessie" asp-for="@Model.WedstrijdSessie" />  
  •         "hidden" id="currentMembers" name="currentMembers" asp-for="@Model.PanelComposition" />  
  •   
  •         class="form-group">  
  •             class="row">  
  •                 class="col-md-6 text-center d-flex align-items-center justify-content-center">  
  •                     "submit" value="Edit" class="btn btn-outline-info"/>  
  •                   
  •                 class="col-md-6 text-center d-flex align-items-center justify-content-center">  
  •                     "button" value="Overview" class="btn btn-outline-info" onclick= "location.href = '@Url.Action("Index", "JuryOpsteller", new { id = Model.WedstrijdSessie })'"/>  
  •                   
  •               
  •           
  •   
  •         

    @Model.PanelName

      
  •   
  •         class="container-fluid mb-3">  
  •             class="container bg-light">  
  •                 @foreach (var panel in Model.PanelComposition)  
  •                 {  
  •                     "border-style: dotted;"/>  
  •   
  •                     class="row formgroup align-items-center">  
  •                         class="col-4">  
  •                             class="control-label">class="font-weight-bold">@panel.Functie:

      
  •                           
  •                         class="col-8">  
  •                             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">  
  •                             for="@panel.JuryName" class="text-danger">  
  •                           
  •                       
  •                 }  
  •               
  •           
  •       
  •   
  • _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?
        
  •             class="col-md-6 text-center d-flex align-items-center justify-content-center">    
  •                 "button" value="Terug naar het overzicht" class="btn btn-outline-info" onclick="location.href = '@Url.Action("Index", "JuryOpsteller", new { id = Model.WedstrijdSessie })'" />    
  •                 
  •             
  •         
  •     
  •     

    @Model.PanelName

        
  •     
  •     class="container-fluid mb-3">    
  •         class="container bg-light">    
  •             @for(var i = 0; i < Model.PanelComposition.Count; i++)    
  •             {    
  •                 int juryCount = i;    
  •                 "border-style: dotted;" />    
  •     
  •                 class="row formgroup align-items-center">    
  •                     class="col-4">    
  •                         class="control-label">class="font-weight-bold">@Model.PanelComposition[i].Functie:

        
  •                         
  •     
  •                     class="col-8">    
  •                         for= "PanelComposition[juryCount].FK_Jury"    
  •                                 asp-items = "Model.JuryMembers"    
  •                                 class="form-control text-center d-flex align-items-center justify-content-center"    
  •                                 name="PanelComposition[@juryCount].FK_Jury"    
  •                                 value="@Model.PanelComposition[juryCount].FK_Jury.ToString()">    
  •                             
  •                         for="@Model.PanelComposition[i].JuryName" class="text-danger">    
  •                         
  •                     
  •             }    
  •             
  •         
  •   
  •   This generates the form the way I need it. 
     
     
    When testing I found the model mapping now works properly, I get the new results I need:
    1. {  
    2.   "WedstrijdSessie": 5828,  
    3.   "PanelName": null,  
    4.   "ClubName": null,  
    5.   "PanelComposition": [  
    6.     {  
    7.       "FK_WedstrijdSessie": null,  
    8.       "SK_JuryOpgave": null,  
    9.       "FK_Jury": 156,  
    10.       "Omschrijving": null,  
    11.       "Functie": null,  
    12.       "Naam": null,  
    13.       "Voornaam": null,  
    14.       "JuryNiveau": null,  
    15.       "JuryNiveauNr": null,  
    16.       "SK_Club": null,  
    17.       "Club": null,  
    18.       "Vlg_PositieToegekend": null,  
    19.       "JuryName": " "  
    20.     },  
    21.     {  
    22.       "FK_WedstrijdSessie": null,  
    23.       "SK_JuryOpgave": null,  
    24.       "FK_Jury": 66,  
    25.       "Omschrijving": null,  
    26.       "Functie": null,  
    27.       "Naam": null,  
    28.       "Voornaam": null,  
    29.       "JuryNiveau": null,  
    30.       "JuryNiveauNr": null,  
    31.       "SK_Club": null,  
    32.       "Club": null,  
    33.       "Vlg_PositieToegekend": null,  
    34.       "JuryName": " "  
    35.     },  
    36.     {  
    37.       "FK_WedstrijdSessie": null,  
    38.       "SK_JuryOpgave": null,  
    39.       "FK_Jury": 143,  
    40.       "Omschrijving": null,  
    41.       "Functie": null,  
    42.       "Naam": null,  
    43.       "Voornaam": null,  
    44.       "JuryNiveau": null,  
    45.       "JuryNiveauNr": null,  
    46.       "SK_Club": null,  
    47.       "Club": null,  
    48.       "Vlg_PositieToegekend": null,  
    49.       "JuryName": " "  
    50.     },  
    51.     {  
    52.       "FK_WedstrijdSessie": null,  
    53.       "SK_JuryOpgave": null,  
    54.       "FK_Jury": 121,  
    55.       "Omschrijving": null,  
    56.       "Functie": null,  
    57.       "Naam": null,  
    58.       "Voornaam": null,  
    59.       "JuryNiveau": null,  
    60.       "JuryNiveauNr": null,  
    61.       "SK_Club": null,  
    62.       "Club": null,  
    63.       "Vlg_PositieToegekend": null,  
    64.       "JuryName": " "  
    65.     },  
    66.     {  
    67.       "FK_WedstrijdSessie": null,  
    68.       "SK_JuryOpgave": null,  
    69.       "FK_Jury": 110,  
    70.       "Omschrijving": null,  
    71.       "Functie": null,  
    72.       "Naam": null,  
    73.       "Voornaam": null,  
    74.       "JuryNiveau": null,  
    75.       "JuryNiveauNr": null,  
    76.       "SK_Club": null,  
    77.       "Club": null,  
    78.       "Vlg_PositieToegekend": null,  
    79.       "JuryName": " "  
    80.     },  
    81.     {  
    82.       "FK_WedstrijdSessie": null,  
    83.       "SK_JuryOpgave": null,  
    84.       "FK_Jury": 129,  
    85.       "Omschrijving": null,  
    86.       "Functie": null,  
    87.       "Naam": null,  
    88.       "Voornaam": null,  
    89.       "JuryNiveau": null,  
    90.       "JuryNiveauNr": null,  
    91.       "SK_Club": null,  
    92.       "Club": null,  
    93.       "Vlg_PositieToegekend": null,  
    94.       "JuryName": " "  
    95.     },  
    96.     {  
    97.       "FK_WedstrijdSessie": null,  
    98.       "SK_JuryOpgave": null,  
    99.       "FK_Jury": 46,  
    100.       "Omschrijving": null,  
    101.       "Functie": null,  
    102.       "Naam": null,  
    103.       "Voornaam": null,  
    104.       "JuryNiveau": null,  
    105.       "JuryNiveauNr": null,  
    106.       "SK_Club": null,  
    107.       "Club": null,  
    108.       "Vlg_PositieToegekend": null,  
    109.       "JuryName": " "  
    110.     },  
    111.     {  
    112.       "FK_WedstrijdSessie": null,  
    113.       "SK_JuryOpgave": null,  
    114.       "FK_Jury": 64,  
    115.       "Omschrijving": null,  
    116.       "Functie": null,  
    117.       "Naam": null,  
    118.       "Voornaam": null,  
    119.       "JuryNiveau": null,  
    120.       "JuryNiveauNr": null,  
    121.       "SK_Club": null,  
    122.       "Club": null,  
    123.       "Vlg_PositieToegekend": null,  
    124.       "JuryName": " "  
    125.     },  
    126.     {  
    127.       "FK_WedstrijdSessie": null,  
    128.       "SK_JuryOpgave": null,  
    129.       "FK_Jury": 64,  
    130.       "Omschrijving": null,  
    131.       "Functie": null,  
    132.       "Naam": null,  
    133.       "Voornaam": null,  
    134.       "JuryNiveau": null,  
    135.       "JuryNiveauNr": null,  
    136.       "SK_Club": null,  
    137.       "Club": null,  
    138.       "Vlg_PositieToegekend": null,  
    139.       "JuryName": " "  
    140.     },  
    141.     {  
    142.       "FK_WedstrijdSessie": null,  
    143.       "SK_JuryOpgave": null,  
    144.       "FK_Jury": 64,  
    145.       "Omschrijving": null,  
    146.       "Functie": null,  
    147.       "Naam": null,  
    148.       "Voornaam": null,  
    149.       "JuryNiveau": null,  
    150.       "JuryNiveauNr": null,  
    151.       "SK_Club": null,  
    152.       "Club": null,  
    153.       "Vlg_PositieToegekend": null,  
    154.       "JuryName": " "  
    155.     },  
    156.     {  
    157.       "FK_WedstrijdSessie": null,  
    158.       "SK_JuryOpgave": null,  
    159.       "FK_Jury": 88,  
    160.       "Omschrijving": null,  
    161.       "Functie": null,  
    162.       "Naam": null,  
    163.       "Voornaam": null,  
    164.       "JuryNiveau": null,  
    165.       "JuryNiveauNr": null,  
    166.       "SK_Club": null,  
    167.       "Club": null,  
    168.       "Vlg_PositieToegekend": null,  
    169.       "JuryName": " "  
    170.     }  
    171.   ],  
    172.   "JuryMembers": null  
    173. }  
     With this, I can continue, though I wonder about 1 thing. As you can see the data I obtain in the post-action only contains a value for FK_Jury. Is there a way to also have the value for Functie filled in? 
    +1
  • Sachin Singh
    0
    Instead of showing us the view you should have posted the controller code so that we could verify why your property is null.
    Make sure you are passing the model in the partial view which contains your Panelcomposition data
    1. public IActionResult Edit (int SelectedPanel)  
    2. {  
    3.   
    4.  var model = db.Juries.Where(x=>x.PanelId==SelectedPanel).ToList();  
    5.  return PartialView("_EditPanel",model);  // check here you have passed the model or not
    6. } 
     
    0
  • Olivier Muhring
    0
    The data displayed in the view is OK. So the model is loaded correctly. It's when new do a round trip, posting the form data, the object the Post action in the Controller receives contains null properties.
    0
  • Olivier Muhring
    0
    I'm afraid I don't understand what you mean. What do you mean?
    0
  • Sachin Singh
    0
    Leave it , if you didn't understand.
    simply change your input to anchor tag and test
    1. "button" value="Overview" class="btn btn-outline-info" onclick= "location.href = '@Url.Action("Index", "JuryOpsteller", new { id = Model.WedstrijdSessie })'"/>   
     To
    1. class="btn btn-outline info" href = '@Url.Action("Index", "JuryOpsteller", new { id = Model.WedstrijdSessie })'"/>   
     
    0