MVC : Inherit Multiple Model object inside View using MVC C#
Let Suppose You have Two Model classes named by Student and Courses.
you want to inherit both class inside same view .
Best practice to inherit both model in same view is to Create a Model class which will have both class list objects.
Example :
Create following Classes In Model folder
Public class Student
{
public int StudentID ;
public string StudentName;
}
Public class Class
{
public int ClassID ;
public string ClassName;
}
public class StudentClassModelView
{
public List<Student> StudentobjList{get; set;}
public List<Class> ClassObjList {get; set;}
}
Now you can use That model class inside you view page.
Inherits="System.Web.Mvc.ViewPage<[NamespaceName].StudentClassModelView>"
No comments:
Post a Comment