I’m using .NET 8 and Blazor in Visual Studio 2022 and I want to move my C# code to a code behind file. There is supposed to be an option called "Extract block to code behind" if you highlight the code block in the .razor
page, I’ve watched a tutorial on this but I don’t have that option in my editor.
Has this been removed from .NET 8 or am I missing a setting of some sort?
It seems to be a general issue with the QuickActions menu, it doesn’t appear if I press Ctrl+. or right click on the menu options
2
Answers
It works OK over here, VS 17.9.3.
Do not "highlight the code block" but just place your cursor in the
@code
word and then press Ctrl+.Visual Studio Information
Solution
Using Razor Comments in the
@code { }
section of the razor file makes is soVisual Studio won’t provide the
Extract block to code behind
Quick ActionIncorrect Example
Example.razor
Correct Example
Example.razor