--- title: ASP.NET Core MVC with EF Core - Update Related Data - 7 of 10 | Microsoft Docs author: tdykstra description: In this tutorial you'll update related data by updating foreign key fields and navigation properties. keywords: ASP.NET Core, Entity Framework Core, related data, joins ms.author: tdykstra manager: wpickett ms.date: 03/07/2017 ms.topic: article ms.assetid: 67bd162b-bfb7-4750-9e7f-705228b5288c ms.technology: aspnet ms.prod: asp.net-core uid: data/ef-mvc/update-related-data --- # Updating related data - EF Core with ASP.NET Core MVC tutorial (7 of 10) 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 1.1 MVC web applications using Entity Framework Core 1.1 and Visual Studio 2017. 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[Main](intro/samples/cu/Controllers/CoursesController.cs?name=snippet_CreateGet)] [!code-csharp[Main](intro/samples/cu/Controllers/CoursesController.cs?name=snippet_CreatePost)] [!code-csharp[Main](intro/samples/cu/Controllers/CoursesController.cs?name=snippet_EditGet)] [!code-csharp[Main](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[Main](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 `