ASP.NET MVC 2 - Checkboxes

Posted by Jay on Stack Overflow See other posts from Stack Overflow or by Jay
Published on 2010-06-11T12:50:59Z Indexed on 2010/06/11 13:12 UTC
Read the original article Hit count: 255

Filed under:
|
|

I'm using string[] roles = Roles.GetAllRoles() to get a string[] of all the ASP.NET membership roles for my application. I'm sending the roles to my view in ViewData and using a foreach to create a set of Checkboxes using <%: Html.CheckBox("RoleCheckBox") %>. There are 3 roles and my view does render 3 checkboxes. When I do a View/Source, I see the checkboxes and their corresponding hidden tags. They all have the same, so there are 6 tags with the name "RoleCheckBox" - 3 that render the checkboxes and 3 that are hidden.

The problem comes when I post the form back to my controller and bind the results - something like public ActionResult Create(Person person, string[] RoleCheckBox). I get FOUR strings and I have no idea where the fourth string ("false") is coming from. I could do some testing by trying various combinations of checks to see which one (hopefully) doesn't change and ignore it but that's just ugly.

Does anyone know why this would be happening?

Thanks,

Jay

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about mvc