[英]Asp.net mvc views for many to many relationship
Good day guys, I created few models that implement a many to many relationship; 美好的一天,我创建了几个实现多对多关系的模型; now I'm having problems correctly formatting/designing the 'Create and Edit' views.
现在我遇到了正确格式化/设计“创建和编辑”视图的问题。 Here are my models:
这是我的模特:
Student Model 学生模特
namespace HMS.Models
{
[Table("Students", Schema ="Admission")]
public class Students : Person
{
[Key]
public int StudentId { get; set; }
[Display(Name = "First Name")]
public string FirstName { get; set; }
[Display(Name = "Last Name")]
public string LastName { get; set; }
// this associate a student with a list of guardian
public virtual ICollection<Guardian> Guardians { get; set; }
}
}
Guardian Model 卫报模型
namespace HMS.Models
{
[Table("Guardians", Schema ="Admission")]
public class Students : Person
{
[Key]
public int GuardianId { get; set; }
[Display(Name = "First Name")]
public string FirstName { get; set; }
[Display(Name = "Last Name")]
public string LastName { get; set; }
// this associate a student with a list of guardian
public virtual ICollection<Student> Students { get; set; }
}
}
StudentGuardian Model StudentGuardian模型
namespace HMS.Models
{
[Table("StudentGuardian", Schema ="Admission")]
public class Students : Person
{
[Key]
public int Id { get; set; }
[Display(Name = "Guardian Id")]
[ForeignKey("GuardianId")]
public int GuardianId { get; set; }
[Display(Name = "Student Id")]
[ForeignKey("StudentId")]
public string StudentId { get; set; }
}
}
A student can have multiple guardians and a guardian multiple students. 学生可以有多名监护人和一名监护人多名学生。 How do I format the 'Create' view to enter these related objects?
如何格式化“创建”视图以输入这些相关对象?
You can design UI as shown below. 您可以设计UI,如下所示。
Note : Here Guardians is a drop down where can be selected more than one Guardian by multiselecting.You have to use multiselecting dropdown for that. 注意: Guardians是一个下拉列表,可以通过多选来选择多个Guardian。您必须使用多选下拉列表。
You can read more about this here : Many to Many Relationship : a step by step View Model approach 您可以在此处阅读更多相关信息: 多对多关系:一步一步查看模型方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.