MvcScaffolding:如何支持实体之间的多对多关系
我开始使用 MVC 3 并使用 MvcScaffolding 来搭建这些模型:
namespace Conference.Models
{
/*
* Speaker can have many session
* And session can have many speakers
*/
public class Speaker
{
public Guid Id { get; set; }
[Required]
public string Name { get; set; }
public string Description { get; set; }
public virtual ICollection<Session> Sessions { get; set; }
}
public class Session
{
public Guid Id { get; set; }
[Required]
public string Title { get; set; }
[Required]
public string Description { get; set; }
[Required]
public DateTime Hour { get; set; }
public virtual ICollection<Speaker> Speakers { get; set; }
}
}
搭建这些模型后,我可以创建会话和演讲者,但在演讲者视图中,我无法选择任何会话,并且在会话视图中我无法选择任何演讲者。
我如何添加这些选项并使它们成为多选选项,以便我可以为一个特定会议选择 10 个发言者,例如?
提前致谢, 约西
I started using MVC 3 and used MvcScaffolding to scaffold these models:
namespace Conference.Models
{
/*
* Speaker can have many session
* And session can have many speakers
*/
public class Speaker
{
public Guid Id { get; set; }
[Required]
public string Name { get; set; }
public string Description { get; set; }
public virtual ICollection<Session> Sessions { get; set; }
}
public class Session
{
public Guid Id { get; set; }
[Required]
public string Title { get; set; }
[Required]
public string Description { get; set; }
[Required]
public DateTime Hour { get; set; }
public virtual ICollection<Speaker> Speakers { get; set; }
}
}
After scaffolding these models, I can create sessions and speakers, but in the speakers view, I cannot choose any sessions, and in the sessions view I cannot choose any speakers.
How can I add these and make them mutliselect options, such that I can choose 10 speakers for one specific session, e.g.?
Thanks in advance,
Yosy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的上下文类中需要这个:(这将创建一个关联表)
You need this in your context class: (this will create an association table)