简体   繁体   中英

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.

After I create a new "Razor Component" file, I can't add the partial class to it.

Where do I add it?

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.

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

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM