dimanche 7 juin 2020

A checkbox list is not overridden when posting a new checkbox list

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:

enter image description here

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.

enter image description here

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:

enter image description here

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: enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

And below I show what is the values of the returned view model enter image description here

enter image description here

enter image description here

And this one is important as this is where the screw up starts happening. This Category is not loaded correctly .... enter image description here

enter image description here

enter image description here

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