Reputation: 225
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
Upvotes: 2
Views: 672
Reputation: 626
Microsoft Visual Studio Enterprise 2022 (64-bit) - Current
Version 17.9.6
The reason this was not working for me was because there were
Razor Comments in the@code { }
section of the razor page
Only use C# Comments in the
@code { }
section of the.razor
file
Using Razor Comments in the @code { }
section of the razor file makes is so
Visual Studio won't provide the Extract block to code behind
Quick Action
Example.razor
<div>Not Working</div>
@code {
private void Method()
{
@* This type of comment DOES NOT work *@
@* Extract code block to code behind is NOT available *@
}
}
Example.razor
<div>This Works</div>
@code {
private void Method()
{
// This type of comment WORKS
/* This type of comment WORKS */
// Extract code block to code behind IS available
}
}
Upvotes: 0
Reputation: 273169
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+.
Upvotes: 3