--- title: "Tutorial: Update related data - ASP.NET MVC with EF Core" description: In this tutorial you update related data by updating foreign key fields and navigation properties. author: tdykstra ms.author: tdykstra ms.custom: mvc ms.date: 03/27/2019 ms.topic: tutorial uid: data/ef-mvc/update-related-data --- # Tutorial: Update related data - ASP.NET MVC with EF Core In the previous tutorial you displayed related data; in this tutorial you'll update related data by updating foreign key fields and navigation properties. The following illustrations show some of the pages that you'll work with. ![Course Edit page](update-related-data/_static/course-edit.png) ![Edit Instructor page](update-related-data/_static/instructor-edit-courses.png) In this tutorial, you: > [!div class="checklist"] > * Customize Courses pages > * Add Instructors Edit page > * Add courses to Edit page > * Update Delete page > * Add office location and courses to Create page ## Prerequisites * [Read related data](read-related-data.md) ## Customize Courses pages When a new `Course` entity is created, it must have a relationship to an existing department. To facilitate this, the scaffolded code includes controller methods and Create and Edit views that include a drop-down list for selecting the department. The drop-down list sets the `Course.DepartmentID` foreign key property, and that's all the Entity Framework needs in order to load the `Department` navigation property with the appropriate `Department` entity. You'll use the scaffolded code, but change it slightly to add error handling and sort the drop-down list. In `CoursesController.cs`, delete the four Create and Edit methods and replace them with the following code: [!code-csharp[](intro/samples/cu/Controllers/CoursesController.cs?name=snippet_CreateGet)] [!code-csharp[](intro/samples/cu/Controllers/CoursesController.cs?name=snippet_CreatePost)] [!code-csharp[](intro/samples/cu/Controllers/CoursesController.cs?name=snippet_EditGet)] [!code-csharp[](intro/samples/cu/Controllers/CoursesController.cs?name=snippet_EditPost)] After the `Edit` HttpPost method, create a new method that loads department info for the drop-down list. [!code-csharp[](intro/samples/cu/Controllers/CoursesController.cs?name=snippet_Departments)] The `PopulateDepartmentsDropDownList` method gets a list of all departments sorted by name, creates a `SelectList` collection for a drop-down list, and passes the collection to the view in `ViewBag`. The method accepts the optional `selectedDepartment` parameter that allows the calling code to specify the item that will be selected when the drop-down list is rendered. The view will pass the name "DepartmentID" to the ``) for the course number in the Edit view. Adding a `