views:

646

answers:

3

Is there a way to post all items in a SelectList (multiselect) to the method of a controller? By default when I use a SelectList it will only post the selected items to the Form.

I have a couple of MultiSelect controls on a View. Using jQuery the user can move items from ListBox1 to ListBox2 and vice versa. When the form is posted I want to be able to determine all items that ended up in ListBox1. However when I evaluate Form["ListBox1"] in my controller it will only provide me a comma delimited list of the SELECTED values - but I want ALL items in ListBox1. Not just the selected ones.

How can I get the View to post ALL items in ListBox1 and not just the selected ones?

+3  A: 

You have to use javascript to select all the ListBox options then all of them will be send to your controller.

Please find this link to be helpfull.

twk
+1  A: 

If you're using jQuery to move items from one to the other, why not user jQuery to fill a hidden form field with all the items from ListBox1?

Will
A: 

This is a nice jquery plugin you could use:

http://www.texotela.co.uk/code/jquery/select/

You can select options using regular expressions, to just select everything

qui