❔ Binding a list<tuple<string,bool> to a form with switches in asp.net
does anyone know how I can send a list of tuple string bool to a
mvc page and display a checkbox in a form that has the string as the name and the bool as the checked or not
i am able to display the switches but I have no idea how to make the submit work ive asked chat gpt and tried everything it keeps returning null. in asp.net 5 mvc btw
27 Replies
Something like this
i cant name the bool and string
List<(bool,string) works but not with names
Yep, you're right
Angius#1586
REPL Result: Success
Result: List<CheckboxItem>
Compile: 556.238ms | Execution: 88.954ms | React with ❌ to remove this embed.
There, much better
Records FTW
yea well i get same problem ive been getting all day
when i submit i never receive anything
Show code
Where's the
name
on the inputs?what do you mean
its in the piblic record CheckboxItem
Inputs need names
: The Input (Form Input) element - HTML: HyperText Markup Language ...
The HTML element is used to create interactive controls for web-based forms in order to accept data from the user; a wide variety of types of input data and control widgets are available, depending on the device and user agent. The element is one of the most powerful and complex in all of HTML due to the sheer number of combinations of input t...
ok let me try that again
minus the last D
still get 0 data in the backend
Open devtools network panel, see what gets sent
ill try with a for loop and use i index
no difference between for and foreach
its not sending a list
it just think its an object with cat attribute and parrot attribute
well i tried this cuz ive seen stack overflow post that seemed to indicate it would work but still doesnt
As I said, makes no difference whether you use a for or a foreach
So, I did some experimenting...
submitting this will get you either a single value,
a: cat
for example, or an array should multiple values be selected, like a: [ cat, dog ]
You should try giving the checkboxes the same name and different values, and binding to List<string>
paramok
yea i got it
i can rebuild the records if needed in backend
thanks
No problem, glad it worked
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.