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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:38:15+00:00 2026-05-16T06:38:15+00:00

Understanding question: 1.) X_IndexViewModel class public class X_IndexViewModel { public List<SelectListItem> CheckBox_1 { get;

  • 0

Understanding question:

1.) “X_IndexViewModel” class

public class X_IndexViewModel
{
   public List<SelectListItem> CheckBox_1 { get; set; } 
   ...
}

2.) XController.cs

public ActionResult Index()
{ 
    X_IndexViewModel viewModel = new X_IndexViewModel
    {
        CheckBox_1 = new List<SelectListItem>() 
        {
            new SelectListItem 
            {   
                Selected = true,
                Text = "some text",
                Value ="another text"
            }
        },    
        ... 
    }
    return View(viewModel);
}

3.) Website “Index.aspx” which inherits “X_IndexViewModel”

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Test.ViewModels.X_IndexViewModel>" %>
   ...      
   <!-- rendering a checkbox -->
   <% foreach (var item in Model.CheckBox_1) { %> 
   <%: Html.CheckBox("CheckBox_1", item.Selected, new {id="CheckBox_1"}) %>
       <label for="CheckBox_1<%: item.Text %>"><%: item.Text %></label> 
   <% } %>
   ...

4) The “real” model class “XModel” contains just a bool to store the information whether the user selected the checkbox or not…

public class XModel
{
    public bool CheckBox_1 {get; set;}
    ...
}

5) And in “XController.cs”

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(XModel model, FormCollection Form)

It surprises me that the argument model of the POST ActionResult method is well filled with true or false for the checkbox.

What I didn’t understand:

I use an instance of the X_IndexViewModel class
( X_IndexViewModel viewModel = new X_IndexViewModel { ... } )
to fill the checkbox with some values (like selected = true or false, etc.).

Then is the website rendered by using the viewModel (where viewModel is an instance of the X_IndexViewModel class).
This works fine because the website inherits X_IndexViwModel.

When the user submits the form is this event (the post event) fetched by the [AcceptVerbs(HttpVerbs.Post)] ActionResult method AND the XModel class properties are filled with the checkbox value.

So my question is:

Where does the binding between the “X_IndexViewModel” and the “XModel” happen?

Which statement says: The returned value of the X_IndexViewModel CheckBox1 should be stored in the XModel property CheckBox1?

  • 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-16T06:38:16+00:00Added an answer on May 16, 2026 at 6:38 am

    After much editting and re-reading your post I think I understand what you are asking. The reason your X_IndexViewModel binds to the CheckBox you created is because the CheckBox is named the exact same as the model property. They are both named CheckBox1.

    This is where th ASP.NET MVC magic happens. It matches up the models properties to the values where the names match up and it is possible to load the values.

    So when the controls are posted, the reverse happens. It doesn’t matter that a different class is being used to receive the data since it is matching up the property names and expected types. Since the data is being posted to a controller that has a model with a property of the same name as the CheckBox control in the HTML then it automatically puts the value in. This all happens behind the scenes by the MVC framework and I like to call it the MVC MAGIC SAUCE.

    If you want to test it, take your exact example and change the XModel bool property name to CheckBox2. The values will not automatically get thrown into the receiving model because the property name no longer matches the HTML’s control name (ID).

    You could also do the same with the original model you pass in to create the view (X_IndexViewModel) as well. Change it to CheckBox2 and the HTML will no longer automatically reflect the value in the model since the model property of CheckBox2 does not match the contols name which is CheckBox1.

    Here are some other links you can read that have more examples and explanations:

    1. ASP.NET MVC Model Binding
    2. ASP.NET MVC 2 Model Binding for a Collection
    3. 6 Tips for ASP.NET MVC Model Binding
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.