2

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!

2
  • What do you mean that you "don't know how to select companies and/or services when creating a new "dinner" and how to save them"? Commented Jan 7, 2010 at 20:07
  • I edited to include the word "multiple". I know how to make a drop-down box to select 1 company, but I don't know how I can make multiple selections and save them. Either with an add-and-remove listbox, a checked list box, etc. Commented Jan 7, 2010 at 20:12

1 Answer 1

2

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 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/

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.