Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CheckBoxListFor posted values weirdness #37

Open
Jogai opened this issue Mar 31, 2015 · 0 comments
Open

CheckBoxListFor posted values weirdness #37

Jogai opened this issue Mar 31, 2015 · 0 comments

Comments

@Jogai
Copy link

Jogai commented Mar 31, 2015

There seems to be a bug in CheckBoxListFor concerning the values used after postback.
I cant get my posted values persist on the checkboxes, and I think it is because of the following inconsistency.
For the record, I have applied the fix from #30
The viewbag holds my data for the checkboxes (mind the selected = true!):

            ViewBag.Sectors = sectors.Select(sector =>
                new SelectListItem
                {
                    Text = sector.Name,
                    Value = sector.Id.ToString(),
                    Selected = true 
                })
            .ToList();

And the helper is using these values ...

@Html.CheckBoxListFor(model => model.SiteNewsSectors, ViewBag.Sectors as IEnumerable<SelectListItem>, new { @class = "form-control" })

... to render everything as expected.
However if I do a submit, and my model is not validated the page is redisplayed, but this time without checked boxes while the list is populated the same way, but for some reason the 'items' parameter has a list without the selected properties set to true.
Another submit reverses this and everything is checked again... If selected is set to false the check boxes are always unchecked as expected. But I cant populate the list with some values set to true that way either (my original problem).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant