大家好,我创建了几个实现多对多关系的模型;现在我在正确格式化/设计“创建和编辑”视图时遇到问题。
这是我的模型:
学生模型
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; }
}
}
守护者模型
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; }
}
}
学生监护人模型
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; }
}
}
一个学生可以有多个监护人,一个监护人可以有多个学生。如何格式化“创建”视图以输入这些相关对象?
您可以设计如下所示的 UI。
Note :这里的监护人是一个下拉菜单,可以通过多选来选择多个监护人。为此,您必须使用多选下拉菜单。
您可以在这里阅读更多相关信息: 多对多关系:一步一步的视图模型方法
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)