views:

18

answers:

1

The customer has a Model property that requires a comma separated list of selected options. We present their select list (DDL) as a multi-choice drop down.

What would the property datatype look like that would autobind multi-selections in the client side HTML select (DDL)?

The select posts data like this:

myOptions=Volvo&myOptions=Mercedes&myOptions=Audi

And we want to automagically bind it back to some property:

IList<string> CarChoices {get;set;}

So the POST action method parameter would be (Carform myForm) which would have myForm.CarChoices which includes a List of the three selected cars?

+1  A: 

Sometimes it is just easier to get your hands dirty and work with the HTML. I suggest doing something like this:

<select multiple>
   <% foreach(var item in Model){ %>
      <option value="<%= item.ID %>"><%= item.Description %></option>
   <% } %>
</select>

obviously your model is your collection. You can also use the ViewData["Whatever"] object to pass data as well, your choice.

Al Katawazi
Dr. Zim
Yeah so when it comes back it is going to look like Volvo,Mercedes,Audi and then you are going to have to parse that using a split function or whatever.
Al Katawazi
give the select list a name like name="CarSelections" and then in your controller add String CarSelections and you will see the list
Al Katawazi