[英]How to add a Partial Class to a component in Blazor in Visual Studio 2019?
I'm not finding where should I click to create a partial class in visual studio 2019.我没有找到我应该在哪里单击以在 Visual Studio 2019 中创建部分类。
After I create a new "Razor Component" file, I can't add the partial class to it.创建新的“Razor Component”文件后,无法向其中添加分部类。
Where do I add it?我在哪里添加它?
There are two ways to add code behind to Razor component:有两种方法可以向 Razor 组件添加代码:
Add Base class and in component add @inherits
this class, how is described in this answer .添加基类并在组件中添加
@inherits
此类,此答案中如何描述。 In this case base class shouldn't be partial.在这种情况下,基类不应该是部分的。
Since October 2019 we can use partial classes .自 2019 年 10 月起,我们可以使用部分类。 You can just add class name with the same name, adding .cs extension, mark it as partial class:
您可以添加同名的类名,添加 .cs 扩展名,将其标记为部分类:
And you don't need to use @inherits
in this case.在这种情况下,您不需要使用
@inherits
。
See Partial class support doc.请参阅部分类支持文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.