Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 2, 2025

The ASP.NET Core Entity Framework Razor Pages tutorial incorrectly documented how SelectList selection works when using the Select Tag Helper with asp-for. The documentation and code comments suggested that the selectedDepartment parameter in the SelectList constructor controls which option is selected, but this is not true.

The Issue

When using the Select Tag Helper with asp-for, the selected option is determined by the model property value, not by the SelectList's selectedDepartment parameter:

// This parameter is IGNORED when using asp-for
DepartmentNameSL = new SelectList(departmentsQuery.AsNoTracking(),
    nameof(Department.DepartmentID),
    nameof(Department.Name),
    selectedDepartment); // <-- Has no effect!

// The selected option is determined by Course.DepartmentID value
<select asp-for="Course.DepartmentID" class="form-control"
        asp-items="@Model.DepartmentNameSL">
    <option value="">-- Select Department --</option>
</select>

Changes Made

Documentation Updates:

  • Clarified that selectedDepartment parameter has no effect when using Select Tag Helper with asp-for
  • Added IMPORTANT note explaining that selection is determined by the model property value
  • Updated misleading explanations about PopulateDepartmentsDropDownList behavior across all moniker ranges

Code Comment Fixes:

  • Replaced misleading comments like "Select current DepartmentID" with accurate explanations
  • Updated all sample code files across versions (cu, cu30, cu50, completed-stages, snapshots)
  • Changed comments to clarify that the model property determines selection, not the SelectList parameter

The fix ensures developers understand that when using asp-for="Course.DepartmentID", the selected option is automatically determined by the value of Course.DepartmentID, making the selectedDepartment parameter redundant in this context.

Fixes #35375.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.


Internal previews

📄 File 🔗 Preview link
aspnetcore/data/ef-rp/update-related-data.md aspnetcore/data/ef-rp/update-related-data

@Copilot Copilot AI changed the title [WIP] Incorrect Method for SelectList selected item Fix incorrect SelectList selected item documentation and misleading comments Sep 2, 2025
Copilot finished work on behalf of tdykstra September 2, 2025 23:57
@Copilot Copilot AI requested a review from tdykstra September 2, 2025 23:57
@tdykstra tdykstra marked this pull request as ready for review September 3, 2025 00:15
@tdykstra
Copy link
Contributor

tdykstra commented Sep 3, 2025

@copilot What are the workflows that need to be approved?

Copy link
Contributor Author

Copilot AI commented Sep 3, 2025

@copilot What are the workflows that need to be approved?

Looking at the repository's workflows, there are several that may require approval:

  1. Status checker (check-for-build-warnings.yml) - This workflow runs on pull_request_target events and checks for build warnings in the documentation. It uses pull_request_target which typically requires approval for first-time contributors.

  2. Quest workflows (quest.yml, quest-bulk.yml) - These handle issue processing and may require approval if they haven't been approved for this contributor before.

  3. Issue processing workflows (blazor-issue-processing.yml, blazor-hybrid-issue-processing.yml) - These are triggered by labels but may also require approval.

The main workflow that's most relevant for this PR is the Status checker which validates the documentation build. Since this uses pull_request_target for security reasons, it typically requires manual approval from a maintainer for contributors who haven't been previously approved.

You should see these workflows listed in the "Checks" section of the PR, and any that require approval will show a pending approval status.

@Copilot Copilot AI requested a review from tdykstra September 3, 2025 00:21
Copilot finished work on behalf of tdykstra September 3, 2025 00:21
@tdykstra
Copy link
Contributor

@copilot

Updated all sample code files across versions (cu, cu30, cu50, completed-stages, snapshots)

your note says you updated code for 3 .NET versions, but there are versions of the sample app for 5, 6, and 9. The PR should address NET 5, 6, and 9 unless there's some reason not to.

Copy link
Contributor Author

Copilot AI commented Oct 10, 2025

@copilot

Updated all sample code files across versions (cu, cu30, cu50, completed-stages, snapshots)
...

I updated all sample apps that have Courses functionality:

  • cu (net2.1)
  • cu30 (net3.0)
  • cu50 (net5.0)
  • cu20snapshots and cu-completed-stages

The cu60 (net6.0) and cu90 (net9.0) directories exist but don't have Courses pages yet - they only have Students pages. cu90 even has a readme.txt stating "Delete this readme file when the code has been updated to .NET 9", indicating it's incomplete.

Should I add Courses functionality to cu60 and cu90 by copying from cu50 and updating the target framework?

Copilot finished work on behalf of tdykstra October 10, 2025 17:06
@tdykstra
Copy link
Contributor

@copilot

Should I add Courses functionality to cu60 and cu90 by copying from cu50 and updating the target framework?

No, that would go beyond the scope of the issue.

Thank you, nice work on this fix.

@Copilot Copilot AI requested a review from tdykstra October 10, 2025 17:24
Copilot finished work on behalf of tdykstra October 10, 2025 17:24
@tdykstra tdykstra requested a review from wadepickett October 10, 2025 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect Method for SelectList selected item

2 participants