Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
These code actions are available when you edit Razor files in Visual Studio.
Applies to: .razor files and ASP.NET Core MVC Razor view files (.cshtml)
Generate method
You can generate a method directly from a method call in a Razor file.
- Place your cursor on a method call that has no matching definition.
- Press Ctrl+. to open Quick Actions and Refactorings.
- Select Generate method.
Visual Studio creates a method signature based on the call site so you can continue implementing logic.
Remove unnecessary directives
Unused Razor directives are faded in the editor. You can remove them by using a code action.
- Place your cursor on a faded
@usingdirective. - Press Ctrl+. to open Quick Actions and Refactorings.
- Select Remove unnecessary directives.
In MVC Razor views, this cleanup also applies to unnecessary @addTagHelper directives.
Sort and Consolidate Usings
Use this code action to organize Razor @using directives.
- Open a Razor file that contains multiple
@usingdirectives. - Press Ctrl+. to open Quick Actions and Refactorings.
- Select Sort and Consolidate Usings.
This action alphabetizes Razor @using directives and removes duplicates.