C# – Read related data – ASP.NET MVC with EF Core – Video

After creating a complex data model, now it is time to display the data, following the tutorial.

The task is actually a challenging one, as far as the data display is in a way partial – in the  “Instructors” view, the instructors are selectable and their courses are displayed. Then the courses are also selectable and the students enlisted are displayed:

Achieving this is actually not a trivial task at all. This is how the Index() method of the InstructorsController.cs looks like:

It “controls” the Index.cshtml view, which is quite complicated as well. The 2 ifs at the end of the code –  @if (Model.Courses != null) and @if (Model.Enrollments != null) show whether the “Select” link is clicked or not. Additionally, I liked the way the CSS class is passed for the row as a string. There is something nice in it:

For everything else, the GitHub code is here: https://github.com/Vitosh/ASP/tree/master/EFCoreAsp.NetMvcWebApp/ContosoUniversity006

Enjoy it! 🙂


Tagged with: , , ,