I am learning ASP.NET MVC. And I have created basic page which has two tables. Below is the model file Courses.cs.
public class Courses
{
public int ID { get; set; }
public string CourseName { get; set; }
public string Description { get; set; }
public int Duration { get; set; }
public virtual ICollection<Instructors> Instructors { get; set; }
}
public class Instructors
{
public int ID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public int CoursesID { get; set; }
public virtual Courses Courses { get; set; }
}
After creating the model. I added the controller and corresponding view got created automatically. Now what I expect in my view is a Courses index.cshtml with field as
- CourseName
- Description
- Duration
Also a Instructor index.cshtml with field as
FirstName
LastName
CoursesID ( It is a foreign key which should be linked to ID (PK) Of Courses table
Now when I open the Instructor index.cshtml file what I see is
<th>
@Html.DisplayNameFor(model => model.Courses.CourseName)
</th>
Why the view has something like model.Courses.CourseName
?
Why the scaffolding does not show the below behavior. I was expecting something like below:
<th>
@Html.DisplayNameFor(model => model.Courses.CoursesID)
</th>
Can some one please explain the behavior?