mardi 4 juin 2019

Handling checkboxes in html table (duplicate and conflicting values)

I have added a checkbox to each table row in my HTML. I need to return the state of each checkbox to the MVC controller so I can update a field on the rows whose box is checked, but my table is showing two values with the checkbox name; one with true and the other with false. Why is this, and how can I return the actual checked value?

I can't get past this issue, so I've been unable to code/test the values being returned to the controller.

In the HTML, I have this: HTML code for table

This is what the generated HTML looks like for the first two checkboxes (IDs 30 and 31). The first checkbox (ID 30) is unchecked, and so I expect FALSE. The second checkbox (ID 31) is checked, and so I expect TRUE. But this is not what I am seeing in the generated source for the HTML (same for IDs 30 and 31, despite the fact that the former is not checked and the latter is checked).

HTML Generated Code

I also do not understand why I see [input name="item.BolAdvanceCycle"...] twice. Once with the id (with value = true) and once hidden (with value = false).

Because the "name" value (name="item.BolAdvanceCycle" appears twice in the generated html with conflicting values (true/false), I'm not sure which is prevailing. I don't even have an idea why the "name" value is represented twice! Is this something to do with checkboxes??

Here is the screen for which I am inquiring:

Table with checkboxes for each row




Aucun commentaire:

Enregistrer un commentaire