views:

555

answers:

1

Hi!

I have a ASP.NET MVC application where I have a HTML.Listbox where the user can add items to it, in the webpage. 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 recevie the information like this.

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

But in my User the Properties RoleGroups is always Null so I check the Request.Form.AllKeys and can't find the key: RoleGroups in there. So I guess the information about the Html.Listbox is never sent when I do the postback!

What have I missed?

+2  A: 

oooo I must have sleept really bad tonight. There is no problem, what I did, was that I forgott to select the item in the listbox after I have added them to the listbox, so of course nothing was sent in the postback...

Well it's fixed now...

Magnus Gladh
an easy solution to this is add a function call to the OnClick of the submit button that quick selects everything in the listboxes. Then nothing is missed.
Andrew Lewis