I'm creating a custom html helper that will allow me to group multiple checkboxes at once. I am using a span element in addition to the checkbox because I need to style the checkbox in a way that can't be done with the native element. The following is sample output of my custom HTML Helper:
<span class="checkbox" id="peopleInvolved-1"></span>
<input id="checkbox-peopleInvolved-1" name="peopleInvolved" style="display:none" type="checkbox" value="1"></input>
<label for="peopleInvolved-1">John Doe</label><br />
The user clicks on the span element (or optionally the label) and it mimics a checkbox through some jQuery magic. That part works great. The part I'm having trouble getting my head around is passing this data back to the controller properly. Currently I'm doing the following to retrieve the results:
public ActionResult Index(string[] peopleInvolved){}
I understand with my current setup that only checked values will return to the controller. I also understand this is the case due to an HTML limitation and that the ASP.NET native workaround is to create an additional hidden element alongside each checkbox. I have no problem adding an additional hidden input element but how would that apply in my scenario? I will have several checkboxes that are grouped together using the same name.
Thanks.