HTML.Listbox in MVC not showing in FormsCollection

I have an ASP.NET MVC application where I have an HTML.Listbox where a user can add items to it in a web page. It looks like this.

<p>
    <label for="groups">Grupper:</label>
    <%= Html.ListBox("RoleGroups", (Model != null ? new SelectList(Model.RoleGroups) : new SelectList(new List<BL.Portal.Domain.Model.RoleGroup>(){})))%>
    <%= Html.ValidationMessage("RoleGroups")%>

    <br />
    <input type="button" id="btnRemoveRoleGroup" name="brnRemoveRoleGroup" value="Ta bort gruppen" />
    <input type="button" id="btnAddRoleGrop" name="btnAddRoleGrop" href="#dialogAddRoleGroup" value="Lägg till en grupp" />
</p>

      

And in the controller I get this kind of information.

[RequiresRole(RoleToCheckFor = RoleEnum.UserCreate)]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult CreateEdit(Model.User user, bool newUser, string confirmedpassword)

      

But in my user the RoleGroups properties are always Null, so I check Request.Form.AllKeys and can't find the key: RoleGroups. So I think the Html.Listbox information is never sent when I postback!

What did I miss?

+1


a source to share


1 answer


Ooh, I must have been feeling really bad today. No problem, what I did was that I didn't want to select an item in the list after I added them to the list, so of course nothing was sent to the postback ...



Well this has now been fixed ...

+2


a source







All Articles