使用 Linq2Sql 在 C# asp.net MVC 中创建和更新多对多关系

发布于 2024-08-17 00:15:46 字数 247 浏览 1 评论 0原文

我按照 NerdDinner 教程在 MVC 中创建了一个 Web 应用程序。我有两个与我的“晚餐”有多对多关系的字段。对于每顿“晚餐”,我需要能够从公司表中选择一个或多个公司,并从服务表中选择一个或多个服务。我已经阅读博客和论坛两天了,但似乎无法弄清楚。我有一个 ServicetoDinner 表,其中包含服务和晚餐的外键,公司也是如此。我知道如何循环显示它们,但我不知道在创建新的“晚餐”时如何选择多个公司和/或服务以及如何保存它们。

我越来越沮丧了。谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

番薯 2024-08-24 00:15:46

使用列表框,您可以通过按住 ctrl 键来选择多个条目。 (确保在显示的页面上对此进行解释)

如果进行编辑,请使用 MultiSelectList 选择已添加的条目(请参阅 让 MultiSelectList 选择项目

然后在视图上显示控件,使用 Html.ListBox

有点复杂但有用的示例:http://ittecture.wordpress.com/2009/04/30/tip-of -the-day-198-asp-net-mvc-listbox-controls/

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文