I created a checkbox list in ASP.NET Core 3.1. The user selects a checkbox and based on the selection new items (checkboxes) are loading in the view.
The problem is that part of the original checkbox list remains even after the new list is loaded.
The view is as follows:
The original view with the selection is shown below. I have revealed the Text and Value attributes to help show which attributes of the checkbox list, do not get refreshed.
As can be seen (note the highlighted sections), the Groceries are selected and the "value" for the Apparel& More is Apparel&More.
After submitting the form, the view becomes as follows:
Notice in this view, that the Groceries remain checked and the "value" in the third checkbox remains the same as in the previous view. They should have changed though based on the view model uploaded.
Below I show the view model posted to the controller and the individual entities: 
And below I show what is the values of the returned view model 
And this one is important as this is where the screw up starts happening. This Category is not loaded correctly .... 
So in summary, the second category "Groceries" remains checked after new values are uploaded. The value for the category Apparel&More seems to persist against the new value of "Fresh Food"
I tried everything I could find about resetting the page, preventing caching etc. but I could not figure out why this is happening. I even tried clearing all the input elements after submitting, using jQuery, but still the same result, somehow the original checkbox list does not want to die. Any help would be appreciated.









Aucun commentaire:
Enregistrer un commentaire