【发布时间】:2012-01-17 12:25:19
【问题描述】:
在 MVC 3 中,我想显示来自两个模型的数据,即。学生和注册在一个视图中。 学生模特
public class Student
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int student_id { get; set; }
public string student_name { get; set; }
public string father { get; set; }
}
招生模式
public class Enrollment
{
[Key]
public int enrollment_id { get; set; }
public string rollno { get; set; }
public int student_id { get; set; }
public string registration_no { get; set; }
public date registration_date { get; set; }
}
我的 ViewModel 看起来像这样
public class StudentEnrollmentViewModel
{
public Student_Info Student_Info { get; set; }
public Enrollment_Info Enrollment_Info { get; set; }
[Key]
public int ID { get; set; }
}
如何从两个模型中检索数据并将其分配给视图模型,以便我可以在视图中显示它?我正在使用存储库设计模式。
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-3 model-view-controller