Reputation: 1
net MVC 5 I have a view that require info from two models. In one modelView i have Student Marks and in the other, I have Student details How do I call both models to the view.
public class Student { [Key] public int StudentNum { get; set; }
public string StudentName { get; set; }
public string StudentSurname { get; set; }
public string Email { get; set; }
}
public class Marks
{
[Key]
public int Mark1 { get; set; }
public int Mark2 { get; set; }
public int Dp { get; set; }
public int StudentNum { get; set; }
public virtual Student Student { get; set; }
}
Upvotes: 0
Views: 105
Reputation: 1224
Create a new View Model which encapsulates both the other view models as,
public class StudentViewModel
{
public Details Details { get; set; }
public Marks Marks { get; set; }
}
and pass it to the view you use. And access by Model.StudentViewModel.Details for getting student details and for marks Model.StudentViewModel.Marks.
Upvotes: 1