mardi 20 janvier 2015

Checking multiple checkboxes in MVC

I've got 5 checkboxes in my View, all set to unchecked upon intial page load. Each of the checkboxes has a textbox associated with it.


One, none or multiple can be checked at any one time, which then gets sent to my Controller.


At the controller level, I'd love to know if there is a more efficient method of finding out which of the many checkboxes have been checked.


At the moment, I'm doing:



if ((checkBox1 == true ) && (checkBox2 == true) && (checkBox3 = true) && (checkBox 4 = true) && (checkBox5 == true))
{
do something with all the textBoxes associated with the checkBoxes that are checked
}
elseif ((checkBox1 == true ) && (checkBox2 == true) && (checkBox3 = true) && (checkBox 4 = true))
{
do something with all the textBoxes associated with the checkBoxes that are checked
}
......and so on


Is there a more efficient method of doing this, or am I going to spend the next few hours copying and pasting :)


Thanks





Aucun commentaire:

Enregistrer un commentaire