tags:

views:

73

answers:

1

Hello

I have a problem with a selectlist, I have 8 items and 3 of them gets the value selected = true in debug, but the rendered Html the item isnt selected.

What might be wrong?

List<SelectListItem> UsergroupID = (from usg in _ug.GetUsergroups().ToList()
                                            join ug in u.Usergroups
                                            on usg.UsergroupID equals ug.UsergroupID into j
                                            select
                                            new SelectListItem
                                            {
                                                Selected = j.Any(),
                                                Value = usg.UsergroupID.ToString(),
                                                Text = usg.UsergroupName
                                            }).ToList();

        ViewData["UsergroupID"] = UsergroupID;

        return View("UserEdit", new UserAdminEditViewModel { User = u, Usergroups = _ug.GetUsergroups() });

And in my view I have:

<%= Html.ListBox("UsergroupID", (IEnumerable<SelectListItem>)ViewData["UsergroupID"]) %>

What's the reason for it not making the 3 items that have selected = true selected in the selectlist? /M

A: 

looks like another bug in MVC to me ... you can refer to this link explaining part of the issue Link

Lil'Monkey
there also seem to be multiple variant of that issue where the selectedValue aint rendering but this one looks like its the most probable
Lil'Monkey
Is there some way I can easily make it a list of checkboxes instead? with a foreach loop?
molgan
i have only used MVC once yet so im not sure about it .. one possibility you could try seems it worked for someone is use the TempData instead is ViewData ... the problem is that TempData got a really short timelife so its prolly gonna expire too fast and then you would lose your information ... anyway i dont recoment using tempdata but if u got no other choice you could give this a try .. gluck
Lil'Monkey
btw sry for the late reply ... at work atm
Lil'Monkey
im also pretty sure someone here could tell you how to go tru it using a foreach loop its probably not that hard ... im jsut a asp/vbscript programmer and kinda new to .net so im not the best person to answer that part of your question :)
Lil'Monkey