简体   繁体   English

如何在 Visual Studio 2019 的 Blazor 中向组件添加分部类?

[英]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 组件添加代码:

  1. 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.在这种情况下,基类不应该是部分的。

  2. 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.请参阅部分类支持文档。

Something like this?像这样的东西? : - razor page with "code-behind" class : - 带有“代码隐藏”类的剃刀页面

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Visual Studio 2019 清理 blazor 组件中的代码 - How to clean/lint the code in a blazor component with visual studio 2019 Visual Studio Community 2019 16.5.3 与 Blazor 应用程序 -> 添加 -> 新项目 -> Razor 组件 -> 路由或组件未呈现 - Visual Studio Community 2019 16.5.3 with Blazor App -> Add -> New Item -> Razor Component -> Route or component is not rendered 在 Blazor 模板 Visual Studio 2019 中自动导航两个 razor 组件 - Navigate two razor component automatically in Blazor template visual studio 2019 如何在 Visual Studio 2019 中添加 .mdf 文件? - How to add .mdf file in Visual Studio 2019? blazor 智能感知无法正常工作 Visual Studio 2019 - blazor intellisense not working visual studio 2019 如何在Visual Studio中的部分类中调用cll方法 - How to cll method in Partial Class in Visual Studio 在 Visual Studio 2019 中添加带有 css 类的 div 的键盘快捷键 - Keyboard shortcut to add a div with a css class in Visual Studio 2019 无法在 Visual Studio 2019 Preview 和 Visual Studio 2019 中添加引用 - Unable to add references in Visual studio 2019 Preview and Visual Studio 2019 Visual Studio:创建在 C# 中创建部分 Class 的加载项 - Visual Studio: Create Add-In That Creates Partial Class in C# 如何将 .Net 框架添加到 Visual Studio preview 2019 项目 - How to add .Net framework to Visual Studio preview 2019 project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM