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

After reading complex the data, it is time to be able to update it. This video fills the following points from the ASP.NET MVC tutorial:

  • Customize Courses pages
  • Add Instructors Edit page
  • Add courses to Edit page
  • Update Delete page
  • Add office location and courses to Create page

I liked explicitly the generation of the checkboxes, making a relation to a corresponding table:

This is the html-razor syntax for the generation:

In the InstructorController.cs the Edit POST and GET methods look quite nicely as well – reading and writing from multiple database tables correctly:

The additional methods PopulateAssignedCourseData() and UpdateInstructorCourses() do what their names say – pretty much rendering relevant course data implementing Update functionailty for the courses:

The Course.cs class used in the method below is in the Models folder:

Everything is available in GitHub – https://github.com/Vitosh/ASP/tree/master/EFCoreAsp.NetMvcWebApp/ContosoUniversity007

Enjoy! 🙂

Tagged with: , , , ,