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?
Open Visual Studio from "Start" -> "All programs" -> "Microsoft Visual Studio". Then, go to "File" -> "New" -> "Project..." then select "Visual C#" -> "Windows" -> "Console application". Then, specify the name such as Partial class or whatever name you wish and the location of the project and click on the "OK" button.
To add a component to the project, right-click on the Pages folder and choose Add -> Razor Component. Refer to the following image. In the Add New Item- Blazor App dialog, provide the name EmployeeCard and click Add.
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.
Something like this? : - razor page with "code-behind" class
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With