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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:50:44+00:00 2026-06-14T06:50:44+00:00

I have a user object, which has three bits of data, the user, their

  • 0

I have a user object, which has three bits of data, the user, their subscription level and a list of all groups that they ARE or COULD be a member of. I need to generate a view that lets me edit this data in a smart way and I want it to be tied to my strongly typed model.

I would like to have one check box for each possible group, and allow the user of my app to check or uncheck boxes to change membership. The problem I’m having is that my action

[HttpPost]
public ActionResult Edit(UserModel usr)
{

}

never receives the values from the checkboxes in the view, but the other properties are correctly populated.

My first view looked like this:

...
@Html.EditorFor(m => m.UserName)
@Html.EditorFor(m => m.Subscription)
@Html.EditorFor(m => m.Membership) // just displays the string and bool values
...

My second stab [also failed]

...
@Html.EditorFor(m => m.UserName)
@Html.EditorFor(m => m.Subscription)

@foreach(var itm in Model.Membership) 
{
    @Html.EditorFor(_ => itm)
}
...

I also tried, and failed to hand craft the <input> tags without using @Html. with no luck.

This is what the UserModel looks like:

public class UserModel
{
    public string UserName { get; set; }
    public int Subscription { get; set; }
    public Dictionary<String, bool> Membership { get; set; } // this is the problem
}
  • 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-14T06:50:45+00:00Added an answer on June 14, 2026 at 6:50 am

    There may be a better way to solve this, but I ended up switching from Dictionary<String,Bool> to a List<SelectListItem>

    The view code that generates correct post data is as follows:

    ...
    <ul>
    @for (int i = 0; i < Model.Membership.Count; i++ )
    {
        <li>
            @Html.HiddenFor(_ => Model.Membership[i].Text)
            @Html.HiddenFor(_ => Model.Membership[i].Value)
            @Html.CheckBoxFor(_ => Model.Membership[i].Selected) @Model.Membership[i].Text
        </li>
    }
    </ul>
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data object which has a base class with three derived classes,
I have an user object for my restful service, which has an userid and
I have a data model object User . My app also has some other
I have a user object represented in JPA which has specific sub-types. Eg, think
I have a script which creates a user-defined object like this: obj = new
I have a User model, which has a state. The state can be either
Ok I have a reservation object which stores all details of event for which
I have a User table which has a foreign key to the UserType table.
I have three tables that I am working with User, Application, ApplicationAdministrator. ApplicationAdministrator is
Say I have an object called data which contains a variety of information. Let's

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.