Skip to content

Remove unused using Microsoft.AspNetCore.Mvc.Rendering from Index.cshtml.cs scaffolding snippets#36842

Open
Copilot wants to merge 2 commits intomainfrom
copilot/remove-unused-usings
Open

Remove unused using Microsoft.AspNetCore.Mvc.Rendering from Index.cshtml.cs scaffolding snippets#36842
Copilot wants to merge 2 commits intomainfrom
copilot/remove-unused-usings

Conversation

Copy link
Contributor

Copilot AI commented Mar 5, 2026

The snippetFullFirstGenerated block in the Razor Pages tutorial's Index.cshtml.cs included using Microsoft.AspNetCore.Mvc.Rendering, which the old scaffolder's Index template does not generate (only Create/Edit templates do). This caused a mismatch between the docs and what users see when following the tutorial.

  • Removed using Microsoft.AspNetCore.Mvc.Rendering; from the snippetFullFirstGenerated block in:
    • snapshot-sample10/Pages/Movies/Index.cshtml.cs (aspnetcore-10.0)
    • snapshot_sample9/Pages/Movies/Index.cshtml.cs (aspnetcore-9.0)
  • Other blocks (SEARCH_NEWPROPS, FIRST_GENERATED_INDEX) retain Mvc.Rendering since SelectList is used there
  • No changes to Create/Delete/Details/Edit files — those correctly match scaffolder output
Original prompt

This section details on the original issue you should resolve

<issue_title>Remove unused usings</issue_title>
<issue_description>### Description

These are the only three namespaces I need for the Index page:

using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using RazorPagesMovie.Models;

You might want to right click on the using statements at the top of all your pages and select "Remove and Sort Usings" to get rid of unneeded usings.
As you write code if you let intelligence finish off class names [hit tab] the VS IDE automatically inserts the needed using statement back in.

Page URL

https://learn.microsoft.com/en-us/aspnet/core/tutorials/razor-pages/page?view=aspnetcore-10.0&tabs=visual-studio

Content source URL

https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/tutorials/razor-pages/page.md

Document ID

15e79e80-8d46-7cd5-c883-6cc0f5940a1b

Platform Id

c731bb82-fefd-1cfc-91d3-8ea9527d2680

Article author

@wadepickett

Metadata

  • ID: 70f6104a-a223-4bb3-4101-f553002b9b26
  • PlatformId: c731bb82-fefd-1cfc-91d3-8ea9527d2680
  • Service: aspnet-core
  • Sub-service: tutorials

Related Issues</issue_description>

<agent_instructions>There is important additional information and direction in the discussion for this issue, in addtion to the issue description. Read all of it before considering the action to take. </agent_instructions>

Comments on the Issue (you are @copilot in this section)

@wadepickett Thanks @smiller7812 for taking the time to file this issue. You are right, that should be reviewed.

The tutorial does need to reflect what the developer would see on their own screen when project or scaffolding templates are used. The templates in some cases put in using statements that would be useful, but are not used in the focused tutorial example. I would guess however there are some in there that are not added by the templates, and yet not used. I'll check.</comment_new>
<comment_new>@wadepickett

🤖 AI Triage Summary

📌 Note to community: This is an automated preliminary analysis to help our documentation team quickly review, determine scope and prioritize this issue. This report is not a resolution or answer to your question—it's an internal triage tool that identifies potentially relevant docs, code samples, and versions to look into. A team member will review this issue and respond. Thank you for your contribution!


This preliminary assessment report was run by: @wadepickett
Date: 2026-03-05
Issue: 36838
Model: GitHub Copilot


Issue Analysis: Remove unused usings from Razor Pages tutorial code samples

✅ Issue Validation

Status: Valid — but requires nuanced action based on scaffolding template analysis

📋 Issue Summary

The issue requests removing unnecessary using statements from code samples in the Razor Pages tutorial. However, investigation of the actual ASP.NET Core scaffolding templates in dotnet/Scaffolding reveals that the using statements present in the documentation samples are intentionally generated by the scaffolding tooling that the tutorial instructs users to run. The tutorial should match what users actually see when following along.

Key Finding: Two Generations of Scaffolding Templates

The dotnet/Scaffolding repository contains two scaffolding codepaths:

Scaffolder Used By Usings Generated Tutorial Uses It?
Old scaffolder (VS.Web.CG.Mvc / aspnet-codegenerator) VS "Add Scaffolded Item" UI + dotnet aspnet-codegenerator CLI Verbose: includes System;, System.Collections.Generic;, System.Linq;, System.Threading.Tasks;, Microsoft.AspNetCore.Mvc.Rendering;, etc. Yes — both the VS tab and VS Code tab use this scaffolder
New scaffolder (dotnet-scaffold / T4 templates under net10.0/) dotnet scaffold aspnet razorpages-crud CLI Minimal: only Microsoft.AspNetCore.Mvc;, Microsoft.AspNetCore.Mvc.RazorPages;, Microsoft.EntityFrameworkCore; + dynamic model/context namespaces No — the tutorial does not currently instruct users to use this

Evidence from the old scaffolder templates (CreatePageModel.cshtml):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;

Evidence from the new .NET 10 scaffolder templates ([IndexModel.tt](https://github.com...


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…shtml.cs snippetFullFirstGenerated blocks

Co-authored-by: wadepickett <10985336+wadepickett@users.noreply.github.com>
Copilot AI changed the title [WIP] Remove unused usings for Index page Remove unused using Microsoft.AspNetCore.Mvc.Rendering from Index.cshtml.cs scaffolding snippets Mar 5, 2026
Copy link
Contributor

@wadepickett wadepickett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved.

@wadepickett wadepickett marked this pull request as ready for review March 5, 2026 19:41
@wadepickett
Copy link
Contributor

wadepickett commented Mar 5, 2026

@copilot, you removed a line of code in 2 files. Those 2 files are referenced by the tutorial articles series in this location and often refer to line numbers when highlighting code lines form that code that is included as an include file. Verify if the highlighting or any other paramameters specifying lines of code for those to code files as includes are still correct. If not, fix them.

aspnetcore/tutorials/razor-pages/

Copy link
Contributor Author

Copilot AI commented Mar 5, 2026

@copilot, you removed a line of code in 2 files. Those 2 files are referenced by the tutorial articles series in this location and often refer to line numbers when highlighting code l...

Verified all references to both modified files across page.md, page9.md, search.md, and search9.md. All code includes use named snippets (?name=snippetFullFirstGenerated, ?name=snippet2FirstGenerated, etc.) rather than absolute line numbers, so the line removal doesn't shift any highlights or ranges.

The only &highlight=12-18 parameters appear on snippet_search_newProps references, which are in the SEARCH_NEWPROPS block — that block was not modified. All other highlight/range parameters reference .cshtml files, not the .cshtml.cs files that were changed. No markdown updates needed.

@wadepickett
Copy link
Contributor

Verified removed code lines did not change the display in the tutorial improperly. All good.

@wadepickett wadepickett requested a review from tdykstra March 5, 2026 20:24
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.

Remove unused usings

3 participants