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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:09:27+00:00 2026-06-18T10:09:27+00:00

I have a model containing a couple of lists: [Display(Name = Facilities)] public List<facility>

  • 0

I have a model containing a couple of lists:

[Display(Name = "Facilities")]
public List<facility> Facilities { get; set; }

[Display(Name = "Accreditations")]
public List<accreditation> Accreditations { get; set; }

I populate these lists initially from my controller:

public ActionResult Register()
{
    var viewModel = new RegisterModel();

    viewModel.Facilities = m_DBModel.facilities.ToList();
    viewModel.Accreditations = m_DBModel.accreditations.ToList();

    return View(viewModel);
}

When they get to my view they are populated with the DB records (great). I then pass the model to the partial view which displays these lists as checkboxes, ready for user manipulation (I have tried based on another suggestion using for loop instead of foreach loop, made no difference):

@model LanguageSchoolsUK.Models.RegisterModel

@foreach (var item in Model.Facilities)
{
    @Html.Label(item.name);
    @Html.CheckBox(item.name, false, new { id = item.facility_id, @class = "RightSpacing", @description = item.description }) 
}

When I submit the form and it ends up back at my controller this time calling the overloaded register function on the controller:

[HttpPost]
public ActionResult Register(RegisterModel model)
{
    if (ModelState.IsValid)
    {
        // Do stuff
    }

    return View(model); 
}

The problem is that the model parameter containing the lists (Facilities and Accreditations) is telling me that the lists are null.

Please can somebody tell me what I am doing wrong, why aren’t they populated with the collections that I originally passed through and hopefully a way of asking whick ones have been checked?

Thanks.

  • 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-18T10:09:28+00:00Added an answer on June 18, 2026 at 10:09 am

    I have tried based on another suggestion using for loop instead of
    foreach loop, made no difference

    Try again, I am sure you will have more luck this time. Oh and use strongly typed helpers:

    @model LanguageSchoolsUK.Models.RegisterModel
    @for (var i = 0; i < Model.Facilities.Count; i++)
    {
        @Html.HiddenFor(x => x.Facilities[i].name)
        @Html.LabelFor(x => x.Facilities[i].IsChecked, Model.Facilities[i].name);
        @Html.CheckBoxFor(
            x => x.Facilities[i].IsChecked, 
            new { 
                id = item.facility_id, 
                @class = "RightSpacing", 
                description = item.description // <!-- HUH, description attribute????
            }
        ) 
    }
    

    Also you will undoubtedly notice from my answer that checkboxes work with boolean fields on your model, not integers, not decimals, not strings => BOOLEANS.

    So make sure that you have a boolean field on your model which will hold the state of the checkbox. In my example this field is called IsChecked but obviously you could feel absolutely free to find it a better name.

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

Sidebar

Related Questions

I have model containing caller_name and call_datetime field. I was able to get number
I have a model containing a boolean with no [Required] attribute public bool IsOptedIn
I have a model containing ImageField which should be resized after uploading. class SomeModel(models.Model):
I have a simple model containing a FileField among others. When I use a
I have an old Xcode project which contains a CoreData model (containing a version
I have a model for assessment criteria which has a :label field containing string
I have a YML file containing fixtures for a Rails model (Comment) which looks
I have a model containing attributes in a multidimensional array. In the template function
I have a model with an property of type icollection. public class myClass{ public
I think I don't unterstand django-haystack properly: I have a data model containing several

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.