--- title: ASP.NET Core MVC with EF Core - Update Related Data - 7 of 10 author: rick-anderson description: In this tutorial you'll update related data by updating foreign key fields and navigation properties. ms.author: tdykstra ms.custom: mvc ms.date: 10/24/2018 uid: data/ef-mvc/update-related-data --- # ASP.NET Core MVC with EF Core - Update Related Data - 7 of 10 [!INCLUDE [RP better than MVC](~/includes/RP-EF/rp-over-mvc-21.md)] ::: moniker range="= aspnetcore-2.0" By [Tom Dykstra](https://github.com/tdykstra) and [Rick Anderson](https://twitter.com/RickAndMSFT) The Contoso University sample web application demonstrates how to create ASP.NET Core MVC web applications using Entity Framework Core and Visual Studio. For information about the tutorial series, see [the first tutorial in the series](intro.md). 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) ![Instructor Edit page](update-related-data/_static/instructor-edit-courses.png) ## Customize the Create and Edit Pages for Courses 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 `