Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8316533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:23:03+00:00 2026-06-08T21:23:03+00:00

UPDATE: Turns out I had skipped one checkbox (4) as can be seen from

  • 0

UPDATE: Turns out I had skipped one checkbox (4) as can be seen from the code. Silly mistake from my side!

I have 16 checkboxes in my view, and I want each one of them bound to an element in a bool array (or BitArray) in the model.

If I try to do this, after submitting the form the controller only gets the first 4 elements of the array (correct values though), so then I tried to allocate more space in the constructor of the model but then the controller would never even get called. Is there any way I can get this to work, or do I need a bool variable for each checkbox?

The array:

public bool[] ActiveSettings { get; set; }

View:

<p><b>Active Settings:</b></p>
<div style="float:left">
@Html.CheckBoxFor(model => model.NetworkSettings.ActiveSettings[0]) val0<br />
@Html.CheckBoxFor(model => model.NetworkSettings.ActiveSettings[1]) val1<br />
@Html.CheckBoxFor(model => model.NetworkSettings.ActiveSettings[2]) val2<br />
@Html.CheckBoxFor(model => model.NetworkSettings.ActiveSettings[3]) val3<br />
@Html.CheckBoxFor(model => model.NetworkSettings.ActiveSettings[5]) val4<br />
@Html.CheckBoxFor(model => model.NetworkSettings.ActiveSettings[6]) val5<br />
@*etc..*@
</div>

Here’s a screenshot of the debugger in the controller (Should be bool[16]):
enter image description here

I tested the same thing with an array of integers using Html.EditorFor, and it worked just fine.
Thanks!

UPDATE:
So what I ended up doing is setting those hidden fields like this:

@Html.CheckBoxFor(model => model.NetworkSettings.ActiveSettings[0]) val0<br />
@Html.Hidden("NetworkSettings.ActiveSettings[0]",false)
@Html.CheckBoxFor(model => model.NetworkSettings.ActiveSettings[1]) val1<br />
@Html.Hidden("NetworkSettings.ActiveSettings[1]",false)

etc…
Here’s a weird note though: I have 16 checkboxes, all I had to do was set hidden fields for the first 5, and then magically all 16 of them worked.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:23:05+00:00Added an answer on June 8, 2026 at 9:23 pm

    what is the rendered html for Checkboxfor? and is the 5th check box unchecked? a checkbox is only submitted in the form collection if the value is true. if the value is false it’s just not sent. MS MVC requires a non-breaking zero-based index of values for an array.

    So if options 1-4 are checked, option 5 is unchecked and options 6-16 are checked only 1-4 hydrated into the view model. 5 is not part of the forms collection and 6-16 are ignored.

    to resolve this a hidden field with the same name as the checkbox needs to be submitted as well. the hidden field has a value of false. The modelbinder will use the checkbox value first. if it’s not present the default value of false was submitted and will be used. the markup looks like this

    <input type="checkbox" id="networksettings_activesettings_4" name="networksettings.activesettings[4]" value="true" />
    <input type="hidden" id="networksettings_activesettings_4_hidden" name="networksettings.activesettings[4]" value="false" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update : It turns out I had (hidden away in my POCO objects) a
UPDATE Turns out I'm just tired. There isn't any problem here sorry for wasting
Update: Turns out this is undocumented behaviour of the NetStream class - NetStream loads
UPDATE: As it turns out, the below is caused by a caching issue on
I have this code that is supposed to echo some values from a MySQL
Update : Alright, it turns out the reason that the below isn't working is
Update: turns out the problem is more complicated than I originally thought. I was
Possible Duplicate: Rails: Routing without plurals gives strange helpers Turns out I had :resources
Update : This is no longer an issue from C# 6, which has introduced
Using EF 4.1 Code First, I have a Member entity and it in turn

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.