Reputation: 31683
I'm not finding where should I click to create a partial class in visual studio 2019.
After I create a new "Razor Component" file, I can't add the partial class to it.
Where do I add it?
Upvotes: 10
Views: 17226
Reputation: 121
Another way: (vs 2022)
Right click the @Code section, pick Quick Actions and Refactorings, select Extract block to code behind.
Upvotes: 5
Reputation: 8637
There are two ways to add code behind to Razor component:
Add Base class and in component add @inherits
this class, how is described in this answer. In this case base class shouldn't be partial.
Since October 2019 we can use partial classes. You can just add class name with the same name, adding .cs extension, mark it as partial class:
And you don't need to use @inherits
in this case.
See Partial class support doc.
Upvotes: 18