Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task<IActionResult> OnPostAsync()
return RedirectToPage("./Index");
}

// Select DepartmentID if TryUpdateModelAsync fails.
// Repopulate departments dropdown. emptyCourse.DepartmentID determines the selected item.
PopulateDepartmentsDropDownList(_context, emptyCourse.DepartmentID);
return Page();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public async Task<IActionResult> OnGetAsync(int? id)
return NotFound();
}

// Select current DepartmentID.
// Populate departments dropdown. Course.DepartmentID determines the selected item.
PopulateDepartmentsDropDownList(_context, Course.DepartmentID);
return Page();
}
Expand Down Expand Up @@ -60,7 +60,7 @@ public async Task<IActionResult> OnPostAsync(int? id)
return RedirectToPage("./Index");
}

// Select DepartmentID if TryUpdateModelAsync fails.
// Repopulate departments dropdown. courseToUpdate.DepartmentID determines the selected item.
PopulateDepartmentsDropDownList(_context, courseToUpdate.DepartmentID);
return Page();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public async Task<IActionResult> OnPostAsync()
return RedirectToPage("./Index");
}

// Select DepartmentID if TryUpdateModelAsync fails.
// Repopulate departments dropdown. emptyCourse.DepartmentID determines the selected item.
PopulateDepartmentsDropDownList(_context, emptyCourse.DepartmentID);
return Page();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public async Task<IActionResult> OnGetAsync(int? id)
return NotFound();
}

// Select current DepartmentID.
// Populate departments dropdown. Course.DepartmentID determines the selected item.
PopulateDepartmentsDropDownList(_context,Course.DepartmentID);
return Page();
}
Expand All @@ -55,7 +55,7 @@ public async Task<IActionResult> OnPostAsync(int? id)
return RedirectToPage("./Index");
}

// Select DepartmentID if TryUpdateModelAsync fails.
// Repopulate departments dropdown. courseToUpdate.DepartmentID determines the selected item.
PopulateDepartmentsDropDownList(_context, courseToUpdate.DepartmentID);
return Page();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public async Task<IActionResult> OnPostAsync()
return RedirectToPage("./Index");
}

// Select DepartmentID if TryUpdateModelAsync fails.
// Repopulate departments dropdown. emptyCourse.DepartmentID determines the selected item.
PopulateDepartmentsDropDownList(_context, emptyCourse.DepartmentID);
return Page();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task<IActionResult> OnGetAsync(int? id)
return NotFound();
}

// Select current DepartmentID.
// Populate departments dropdown. Course.DepartmentID determines the selected item.
PopulateDepartmentsDropDownList(_context, Course.DepartmentID);
return Page();
}
Expand All @@ -61,7 +61,7 @@ public async Task<IActionResult> OnPostAsync(int? id)
return RedirectToPage("./Index");
}

// Select DepartmentID if TryUpdateModelAsync fails.
// Repopulate departments dropdown. courseToUpdate.DepartmentID determines the selected item.
PopulateDepartmentsDropDownList(_context, courseToUpdate.DepartmentID);
return Page();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public async Task<IActionResult> OnPostAsync()
return RedirectToPage("./Index");
}

// Select DepartmentID if TryUpdateModelAsync fails.
// Repopulate departments dropdown. emptyCourse.DepartmentID determines the selected item.
PopulateDepartmentsDropDownList(_context, emptyCourse.DepartmentID);
return Page();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task<IActionResult> OnGetAsync(int? id)
return NotFound();
}

// Select current DepartmentID.
// Populate departments dropdown. Course.DepartmentID determines the selected item.
PopulateDepartmentsDropDownList(_context, Course.DepartmentID);
return Page();
}
Expand All @@ -61,7 +61,7 @@ public async Task<IActionResult> OnPostAsync(int? id)
return RedirectToPage("./Index");
}

// Select DepartmentID if TryUpdateModelAsync fails.
// Repopulate departments dropdown. courseToUpdate.DepartmentID determines the selected item.
PopulateDepartmentsDropDownList(_context, courseToUpdate.DepartmentID);
return Page();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public async Task<IActionResult> OnPostAsync()
return RedirectToPage("./Index");
}

// Select DepartmentID if TryUpdateModelAsync fails.
// Repopulate departments dropdown. emptyCourse.DepartmentID determines the selected item.
PopulateDepartmentsDropDownList(_context, emptyCourse.DepartmentID);
return Page();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public async Task<IActionResult> OnGetAsync(int? id)
return NotFound();
}

// Select current DepartmentID.
// Populate departments dropdown. Course.DepartmentID determines the selected item.
PopulateDepartmentsDropDownList(_context, Course.DepartmentID);
return Page();
}
Expand Down Expand Up @@ -60,7 +60,7 @@ public async Task<IActionResult> OnPostAsync(int? id)
return RedirectToPage("./Index");
}

// Select DepartmentID if TryUpdateModelAsync fails.
// Repopulate departments dropdown. courseToUpdate.DepartmentID determines the selected item.
PopulateDepartmentsDropDownList(_context, courseToUpdate.DepartmentID);
return Page();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public async Task<IActionResult> OnPostAsync()
return RedirectToPage("./Index");
}

// Select DepartmentID if TryUpdateModelAsync fails.
// Repopulate departments dropdown. emptyCourse.DepartmentID determines the selected item.
PopulateDepartmentsDropDownList(_context, emptyCourse.DepartmentID);
return Page();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public async Task<IActionResult> OnGetAsync(int? id)
return NotFound();
}

// Select current DepartmentID.
// Populate departments dropdown. Course.DepartmentID determines the selected item.
PopulateDepartmentsDropDownList(_context, Course.DepartmentID);
return Page();
}
Expand Down Expand Up @@ -60,7 +60,7 @@ public async Task<IActionResult> OnPostAsync(int? id)
return RedirectToPage("./Index");
}

// Select DepartmentID if TryUpdateModelAsync fails.
// Repopulate departments dropdown. courseToUpdate.DepartmentID determines the selected item.
PopulateDepartmentsDropDownList(_context, courseToUpdate.DepartmentID);
return Page();
}
Expand Down
14 changes: 8 additions & 6 deletions aspnetcore/data/ef-rp/update-related-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ Create a `Pages/Courses/DepartmentNamePageModel.cs` file with the following code

[!code-csharp[](intro/samples/cu50/Pages/Courses/DepartmentNamePageModel.cs)]

The preceding code creates a <xref:Microsoft.AspNetCore.Mvc.Rendering.SelectList> to contain the list of department names. If `selectedDepartment` is specified, that department is selected in the `SelectList`.
The preceding code creates a <xref:Microsoft.AspNetCore.Mvc.Rendering.SelectList> to contain the list of department names. The `selectedDepartment` parameter allows the calling code to specify the item that will be selected when the drop-down list is rendered. However, when using the Select Tag Helper with `asp-for`, the selected item is determined by the model property value (such as `Course.DepartmentID`), not by the `selectedDepartment` parameter.

> [!IMPORTANT]
> When using the Select Tag Helper with `asp-for="Course.DepartmentID"`, the selected option is automatically determined by the value of `Course.DepartmentID`. The `selectedDepartment` parameter passed to the SelectList constructor is ignored in this scenario.
The Create and Edit page model classes will derive from `DepartmentNamePageModel`.

### Update the Course Create page model
Expand Down Expand Up @@ -77,7 +79,7 @@ Update `Pages/Courses/Edit.cshtml.cs` with the following code:

[!code-csharp[](intro/samples/cu50/Pages/Courses/Edit.cshtml.cs?highlight=8,28,35,36,40-66)]

The changes are similar to those made in the Create page model. In the preceding code, `PopulateDepartmentsDropDownList` passes in the department ID, which selects that department in the drop-down list.
The changes are similar to those made in the Create page model. In the preceding code, `PopulateDepartmentsDropDownList` passes in the department ID. When using the Select Tag Helper with `asp-for="Course.DepartmentID"`, the selected item in the drop-down list is determined by the value of `Course.DepartmentID`, not by the `selectedDepartment` parameter passed to the SelectList constructor.

### Update the Course Edit Razor page

Expand Down Expand Up @@ -253,7 +255,7 @@ Create a `Pages/Courses/DepartmentNamePageModel.cs` file with the following code

[!code-csharp[](intro/samples/cu30/Pages/Courses/DepartmentNamePageModel.cs)]

The preceding code creates a <xref:Microsoft.AspNetCore.Mvc.Rendering.SelectList> to contain the list of department names. If `selectedDepartment` is specified, that department is selected in the `SelectList`.
The preceding code creates a <xref:Microsoft.AspNetCore.Mvc.Rendering.SelectList> to contain the list of department names. The `selectedDepartment` parameter allows the calling code to specify the item that will be selected when the drop-down list is rendered. However, when using the Select Tag Helper with `asp-for`, the selected item is determined by the model property value (such as `Course.DepartmentID`), not by the `selectedDepartment` parameter.

The Create and Edit page model classes will derive from `DepartmentNamePageModel`.

Expand Down Expand Up @@ -300,7 +302,7 @@ Update `Pages/Courses/Edit.cshtml.cs` with the following code:

[!code-csharp[](intro/samples/cu30/Pages/Courses/Edit.cshtml.cs?highlight=8,28,35,36,40-66)]

The changes are similar to those made in the Create page model. In the preceding code, `PopulateDepartmentsDropDownList` passes in the department ID, which selects that department in the drop-down list.
The changes are similar to those made in the Create page model. In the preceding code, `PopulateDepartmentsDropDownList` passes in the department ID. When using the Select Tag Helper with `asp-for="Course.DepartmentID"`, the selected item in the drop-down list is determined by the value of `Course.DepartmentID`, not by the `selectedDepartment` parameter passed to the SelectList constructor.

### Update the Course Edit Razor page

Expand Down Expand Up @@ -470,7 +472,7 @@ The Courses/Create and Courses/Edit pages each need a list of department names.

[!code-csharp[](intro/samples/cu/Pages/Courses/DepartmentNamePageModel.cshtml.cs?highlight=9,11,20-21)]

The preceding code creates a <xref:Microsoft.AspNetCore.Mvc.Rendering.SelectList> to contain the list of department names. If `selectedDepartment` is specified, that department is selected in the `SelectList`.
The preceding code creates a <xref:Microsoft.AspNetCore.Mvc.Rendering.SelectList> to contain the list of department names. The `selectedDepartment` parameter allows the calling code to specify the item that will be selected when the drop-down list is rendered. However, when using the Select Tag Helper with `asp-for`, the selected item is determined by the model property value (such as `Course.DepartmentID`), not by the `selectedDepartment` parameter.

The Create and Edit page model classes will derive from `DepartmentNamePageModel`.

Expand Down Expand Up @@ -517,7 +519,7 @@ Replace the code in `Pages/Courses/Edit.cshtml.cs` with the following code:

[!code-csharp[](intro/samples/cu/Pages/Courses/Edit.cshtml.cs?highlight=8,28,35,36,40,47-999)]

The changes are similar to those made in the Create page model. In the preceding code, `PopulateDepartmentsDropDownList` passes in the department ID, which select the department specified in the drop-down list.
The changes are similar to those made in the Create page model. In the preceding code, `PopulateDepartmentsDropDownList` passes in the department ID. When using the Select Tag Helper with `asp-for="Course.DepartmentID"`, the selected item in the drop-down list is determined by the value of `Course.DepartmentID`, not by the `selectedDepartment` parameter passed to the SelectList constructor.

Update `Pages/Courses/Edit.cshtml` with the following markup:

Expand Down