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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:37:41+00:00 2026-05-14T06:37:41+00:00

I have a strong type view of type List<List<MyViewModelClass>> The outer list will always

  • 0

I have a strong type view of type

List<List<MyViewModelClass>>

The outer list will always have two lists of List<MyViewModelClass>. For each of the two outer lists I want to display a group of checkboxes. Each set can have an arbitrary number of choices.

My view model class looks similar to this:

public class MyViewModelClass
{
    public Area Area { get; set; }

    public bool IsGeneric { get; set; }

    public string Code { get; set; }

    public bool IsChecked { get; set; }
}

So the final view will look something like:


Please select those that apply:

First set of choices:

  • x Option 1
  • x Option 2
  • x Option 3
  • etc.

Second set of choices:

  • x Second Option 1
  • x Second Option 2
  • x Second Option 3
  • x Second Option 4
  • etc.

Checkboxes should display MyViewModelClass.Area.Name, and their value should be related to MyViewModelClass.Area.Id. Checked state is of course related to MyViewModel.IsChecked.

Question

I wonder how should I use Html.CheckBox() or Html.CheckBoxFor() helper to display my checkboxes? I have to get these values back to the server on a postback of course.

I would like to have my controller action like one of these:

public ActionResult ConsumeSelections(List<List<MyViewModelClass>> data)
{
    // process data
}

public ActionResult ConsumeSelections(List<MyViewModelClass> first, List<MyViewModelClass> second)
{
    // process data
}

If it makes things simpler, I could make a separate view model type like:

public class Options
{
    public List<MyViewModelClass> First { get; set; }

    public List<MyViewModelClass> Second { get; set; }
}

As well as changing my first version of controller action to:

public ActionResult ConsumeSelections(Options data)
{
    // process data
}
  • 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-14T06:37:42+00:00Added an answer on May 14, 2026 at 6:37 am

    Solution

    It turns out this is not so complicated at all. All you have to do is name your controls appropriately and everything will be bound together as it should be. So. Whatever your controls, they should always be named like:

    name="first[0].propName"
    name="first[1].propName"
    name="first[2].propName"
    name="first[3].propName"
    ...
    
    // or
    name="first[0].data[0].property"
    name="first[0].data[1].property"
    name="first[0].data[2].property"
    ...
    name="first[1].data[0].property"
    name="first[1].data[1].property"
    ...
    

    All these will get bound to List<SomeType> first controller action parameter (the second one has another collection inside a collection).

    Very important note
    If you add/remove these controls dynamically using Javascript, you have to make sure, that indexes are consecutive starting from 0, and not having any gaps. And you will have a nice working app with dynamic number of elements in a collection.

    You can read about it in my blog post as well.

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

Sidebar

Related Questions

I have a method that returns a list of type string. I want to
Overview: I have an Expandable List View which displays items of the type ToDoElement
For example if i have to create custom list view about type of food,
I have created a strongly type view. I want to pass IEnumerable Object or
I have a string of below type. [test1,3,(257,305,435,900)] Now i want to split this
I have a class class PCB { public: struct { string type; **linklist list;**//refer
I have a bean of type string[] which has two or more values. I
I have 3 files: 1) cpf0.ml type string = char list type url =
i have a list of PlanItems bind to telerik RadGrid and have two views
I need to add two text view to the list view as shown in

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.