Home > front end >  Can't get selected values of dynamically created Select List list to objects in Razor Pages
Can't get selected values of dynamically created Select List list to objects in Razor Pages

Time:08-25

I am trying to assing the selected values of Select lists to fields in a complex object list in a loop but its creating new instances of the objects with the selected value and overwriting the existing objects. Tried adding inputs for other fields but it doesnt copy complex variables and leaves them null or empty again.

I have a list of Ball objects with a string id, integer weight value and a dictionary of Color objects and boolean value(I will also use that dictionary for checkboxes). I am initializing the list and dictionary and creating Select Lists in a foreach loop with index. When I submit via Save button I expect to fill the SelectedColorId field of the current Ball object with the selected colorId but it creates a new Ball object with SelectedColorId field only and others null. I tried copying other values with input tags but still couldnt get the complex objects like availableColors dictionary.

How can I assing the selected values to existing objects field without using js or jquery?

enter image description here

  • Related