How to add a Partial Class to a component in Blazor in Visual Studio 2019?

筅森魡賤 提交于 2020-07-23 07:46:21

问题


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?


回答1:


Something like this? : - razor page with "code-behind" class




回答2:


There are two ways to add code behind to Razor component:

  1. 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.

  2. 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.



来源:https://stackoverflow.com/questions/60551182/how-to-add-a-partial-class-to-a-component-in-blazor-in-visual-studio-2019

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!