Notice that in order to be able to add courses to the As an alternative to doing this in controller code, you could do it in the Instructor model by changing the property getter to automatically create the collection if it doesn't exist, as shown in the following example: Test by running the app and creating an instructor.
As explained in the CRUD tutorial, the Entity Framework implicitly implements transactions.
This will fix the line breaks so that they look like what you see here.
The indentation doesn't have to be perfect, but the lines must each be on a single line as shown or you'll get a runtime error.
navigation property before it checks for validation errors and adds the new instructor to the database.
Courses are added even if there are model errors so that when there are model errors (for an example, the user keyed an invalid date), and the page is redisplayed with an error message, any course selections that were made are automatically restored.
When the check boxes are initially rendered, those that are for courses assigned to the instructor have checked attributes, which selects them (displays them checked).
To optimize performance of the Course Details and Delete pages, add .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 also include code that sets the selected item when they redisplay the page after an error.To facilitate efficient lookups, the latter two collections are stored in Note When you paste the code in Visual Studio, line breaks will be changed in a way that breaks the code.Press Ctrl Z one time to undo the automatic formatting.
For information about the tutorial series, see the first tutorial in the series.