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
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?