[英]Parent and child record added on single MVC View
In ASP.NET MVC 5 and EF6 Code First, i have a case in which a student can have one to many addresses. 在ASP.NET MVC 5和EF6 Code First中,我遇到一种情况,即学生可以拥有一个或多个地址。 Now i want to use Student model in View to add both the record Student and Addresses of student.
现在,我想在View中使用Student模型来添加记录Student和Student的地址。 But the problem is i cant add addresses of student, is there any appropriate solution for this solution
但问题是我无法添加学生的地址,此解决方案是否有合适的解决方案
Here is the example code 这是示例代码
public class Student
{
public Student()
{ }
[Key]
public int StudentID { get; set; }
[Required]
public string Name { get; set; }
public virtual List<Address> Address { get; set; }
}
public class Address
{
public Address()
{
}
[Key]
public int AddressID { get; set; }
[ForeignKey("Student")]
public int StudentID { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string PostalCode { get; set; }
public string State { get; set; }
public string City { get; set; }
public string Country { get; set; }
public virtual Student Student { get; set; }
}
为地址创建“列表框”并通过“列表传递”确实可以为您提供帮助,您可以在此处粘贴控制器代码吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.