--- title: Updating related data | Microsoft Docs author: tdykstra description: keywords: ASP.NET Core, ms.author: tdykstra manager: wpickett ms.date: 10/14/2016 ms.topic: article ms.assetid: 67bd162b-bfb7-4750-9e7f-705228b5288c ms.technology: aspnet ms.prod: aspnet-core uid: data/ef-mvc/update-related-data --- # Updating related data The Contoso University sample web application demonstrates how to create ASP.NET Core 1.0 MVC web applications using Entity Framework Core 1.0 and Visual Studio 2015. 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 `