views:

286

answers:

1

I have created a web app in MVC following the NerdDinner tutorial. I have 2 fields that have many to many relationship with my "dinner". For each "dinner", I need to be able to select one or more Companies from a Company table and one or more Services from a Service table. I've been reading blogs and forums for 2 days, but can't seem to figure it out. I have a ServicetoDinner table with foreign keys to the service and the dinner, and the same for the Companies. I know how to loop through to display them, but I don't know how to select multiple companies and/or services when creating a new "dinner" and how to save them.

I'm getting frustrated. Thanks!

+1  A: 

Use a ListBox that lets you select multiple entries by holding ctrl. (Make sure you explain this on the page being displayed)

If editing, select the already added entries using MultiSelectList (see http://stackoverflow.com/questions/1340555/getting-multiselectlist-to-select-items)

Then to show the control on the view use Html.ListBox

A bit over complex but useful example: http://ittecture.wordpress.com/2009/04/30/tip-of-the-day-198-asp-net-mvc-listbox-controls/

bortao
Thank you. It's easy to find information when you know to search for "MultiSelectList"! But, much harder when you don't know the term to search for.
RememberME