I'm learning asp.net MVC and I'm trying to build an application but i can't have data displayed in my view. I've search here but wasn't able to find an answer to this issue. I have a model structure with Person which is my base class and two other classes that inherited from Person - Professor and Student. What i want is when i click the Students tab in my application it displays only students data and when i click Professors it displays only professors data with their common data and specific for each type. Right now i have only one table "Person" with students and professors attributes. Thanks in advance!!
Here is my base class Person and subclasses Professor and Student
public abstract class Person
{
public virtual int PersonID { get; set; }
public virtual string FirstName { get; set; }
public virtual string LastName { get; set; }
public virtual string Email { get; set; }
public virtual string Login { get; set; }
public virtual string Senha { get; set; }
public virtual string Address { get; set; }
}
public class Professor : Person
{
public string CREF { get; set; }
public string Education { get; set; }
public virtual ICollection<Session> Sessions { get; set; }
}
public class Student : Person
{
public DateTime SessionStart { get; set; }
public DateTime SessionEnd { get; set; }
public virtual ICollection<TSession> Sessions { get; set; }
}
and here is my StudentController
public class StudentController : Controller
{
private SessionContext db = new SessionContext();
public ActionResult Index()
{
return View(db.People.ToList());
}
}
Here is my Index studentView
....
<table class="table">
<tr>
<th>@Html.DisplayNameFor(model => model.FirstName)</th>
<th>@Html.DisplayNameFor(model => model.LastName)</th>
....
</tr>
@foreach (var item in Model) {
<tr>
<td>@Html.DisplayFor(modelItem => item.FirstName)</td>
<td>@Html.DisplayFor(modelItem => item.LastName)</td>
....
</tr>
}
</table>