繁体   English   中英

Asp.net mvc对很多很多关系的看法

[英]Asp.net mvc views for many to many relationship

美好的一天,我创建了几个实现多对多关系的模型; 现在我遇到了正确格式化/设计“创建和编辑”视图的问题。 这是我的模特:

学生模特

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; }
    }
}

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; }               
    }
}

学生可以有多名监护人和一名监护人多名学生。 如何格式化“创建”视图以输入这些相关对象?

您可以设计UI,如下所示。

注意: Guardians是一个下拉列表,可以通过多选来选择多个Guardian。您必须使用多选下拉列表。

在此输入图像描述

您可以在此处阅读更多相关信息: 多对多关系:一步一步查看模型方法

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM