开发者

Creating and Updating many to many relationships in C# asp.net MVC with Linq2Sql

开发者 https://www.devze.com 2022-12-16 05:06 出处:网络
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 Co

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.开发者_JAVA百科 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!


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/

0

精彩评论

暂无评论...
验证码 换一张
取 消