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

  • Home
  • SEARCH
  • 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 6668081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:00:05+00:00 2026-05-26T03:00:05+00:00

Today I faced a problem and I’m not able to get weather I understand

  • 0

Today I faced a problem and I’m not able to get weather I understand something wrong about ASP.NET MVC (and possibly MVC in general) or I miss something about it’s implementation.

So, I have a simple model hierarchy:

public class Child
{
    public Child(int notId, bool isSelected, string text)
    {
        NotId = notId;
        IsSelected = isSelected;
        Text = text;
    }

    public Child(){}

    // naming: just to make sure I do not mess with some
    // conventional infrastructure
    public int NotId { get; set; }
    public bool IsSelected { get; set; }
    public string Text { get; set; }
}

public class Parent
{
    public List<Child> Children { get; set; } 
}

Here is my HomeController‘s Edit actions:

[HttpGet]
public ActionResult Edit()
{
    var parent = new Parent
                    {
                        Children = new List<Child>
                                {
                                    new Child(1, true, "a"),
                                    new Child(2, false, "b")
                                }
                    };
    return View(parent);
}

[HttpPost]
public ActionResult Edit(Parent parent)
{
    parent.Children = new List<Child>
                        {
                            new Child(4, false, "c"),
                            new Child(5, true, "d")
                        };
    return View(parent);
}

Hese is my Edit.aspx view:

<!-- Standart HTML elements ommited --> 
<% Html.BeginForm(); %>
<% for (var i = 0; i < Model.Children.Count; i++){%>
<div>
    <%=Html.LabelFor(m => m.Children[i].IsSelected)%>
    <%=Html.EditorFor(m => m.Children[i].IsSelected)%> <!-- lamda -->
    <%=Html.CheckBoxFor(m => m.Children[i].IsSelected)%> <!-- lamda -->
    <%=Html.CheckBox("A", Model.Children[i].IsSelected)%> <!-- simple -->
</div>
<% } %>

<input type="submit" value="Submit" />
<% Html.EndForm();%>

The point is that in Edit (HttpGet) method I create Parent instance with two child Child elements having their IsSelected properties set to true and false respectively. After form is submitted in Edit (HttpPost) method I give my Parent object a new children collection of two Child elements with their IsSelected properties set to false and true respectively (that is opposite from HttpGet method) and call View() method to render my model.

But what I get after submit is checkboxes, rendered with Html.EditorFor() and Html.CheckBoxFor() do not changes their state. It looks like Html.EditorFor() and Html.CheckBoxFor() methods take data NOT from my model but from a posted form data.

Could someone please explain me what is going on here and why ASP.NET MVC refuses to render my model? Workarounds? Fixes to my code?

Thanks in advance.

P.S. I noticed this behavior in MVC2 and thought this was some kind of a bug, but when I tested this with MVC3 it did the same thing.

  • 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-05-26T03:00:06+00:00Added an answer on May 26, 2026 at 3:00 am

    Html.CheckBoxFor() methods take data NOT from my model but from a
    posted form data.

    That is correct.

    You’ll have to clear ModelState with ModelState.Clear() to get these checkboxes to use the actual Model value and not the form data.

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

Sidebar

Related Questions

Today I faced a strange problem in C#. I have an ASP.NET page where
Today we faced a quite simple problem that were made even simpler by the
Today I was listening to the Hanselminutes show about .NET 3.5 SP1...What's inside ,
Today I stumbled about a Problem which seems to be a bug in the
Today when I was in computer organization class, teacher talked about something interesting to
Today I faced a strange problem. I have an application which is the same
I am using form authentication inmy ASP.NET 2.0 website. Today during testing i was
Today I faced the following problem: I registered a new user on my Joobla
Today I faced a problem that there is one memory leak in my iphone
I faced a problem today which has happened to me several times before. I

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.