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 8249263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:28:41+00:00 2026-06-07T23:28:41+00:00

Currently I am attempting to create a mass update based on a series of

  • 0

Currently I am attempting to create a mass update based on a series of checkboxes. I can’t seem to find the correct way to do it using the entity framework.

I am using ASP.Net 4 with MVC3 and Razor.

Here is the code I have so far.

View Page (Working Properly)

@model List<LeagueCounters.Models.champion>
<form name="setFree id="setFree" method="POST" action="/Champion/SetFree">
    @foreach (var item in Model)
    {
        if (item.isFree == true)
        {
           <input type="checkbox" id="@item.id" checked="checked" /> @Html.DisplayFor(modelItem => item.displayName)  
        }
        else
        {
            <input type="checkbox" id="@item.id" /> @Html.DisplayFor(modelItem => item.displayName)
        }
    }
<p><input type="submit" value="Save" /></p>

Controller (Errors)

[HttpPost, Authorize(Roles = "Admin")]
public ActionResult SetFree(FormCollection fcMain)
{
     var sortedList = from c in _db.champions
                      orderby c.name
                      select c;
     int counter = 0;
     foreach (champion champ in sortedList)
     {
         if (fcMain[counter].Contains("true"))
            champ.isFree = true;
         else
            champ.isFree = false;

         _db.champions.Attach(champ);
         _db.ObjectStateManager.ChangeObjectState(champ, EntityState.Modified);

         counter++;
     }

     _db.SaveChanges();

     return View();
}

Errors

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Question

How do I properly cycle through the checkboxes in the controller? And will my mass update code work once I get to that point?

Thanks in Advance.

  • 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-07T23:28:44+00:00Added an answer on June 7, 2026 at 11:28 pm

    The problem here is that only the checked checkboxes are posted to the server. So you can’t expect all of your checkbox keys to be present in the form collection. To workaround this behavior Html.CheckBoxFor creates an additional hidden field with checkbox so the result could be read on the server side. I am not sure how would you use strongly typed helper here because you are rendering data in a loop. I think you can have a look at this google search

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently attempting to create a tabbed interface in a web application, and based
I'm currently attempting to create a browser-based Calendar which allows jobs or meetings, etc.
I'm attempting to create Data Access Layer for my web application. Currently, all datatables
I'm playing with using Regex to modify Twitter posts. I'm currently attempting to trim
Some background: I am attempting to create a DirectShow source filter based on the
I am attempting to create Domino DateTime objects in arbitrary time zones using the
I am attempting to create a Dictionary from my DataTable. Currently i do this
I am currently attempting to create a bash script that will check inside of
I'm attempting to create something like a read-only console window using apache wicket. Essentially
I am attempting to create an API with Rails using BDD with RSpec. Rails

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.