Using Razor Class Libraries
Learn about incorporating Entity Framework Core functionality in ASP.NET Core Razor Pages.
Everything related to a Razor Page can be compiled into a class library for easier reuse in multiple projects. With ASP.NET Core 3.0 and later, this can include static files such as HTML, CSS, JavaScript libraries, and media assets such as image files. A website can either use the Razor Page’s view as defined in the class library or override it.
Disabling compact folders for Visual Studio Code
Before implementing our Razor class library, we will learn about a Visual Studio Code feature, which is a compact folder feature. The compact folders feature means that nested folders, such as /Areas/MyFeature/Pages/
are shown in a compact form if the intermediate folders in the hierarchy do not contain files, as shown in the figure:
If we would like to disable the Visual Studio Code compact folders feature, complete the following steps:
On Windows, navigate to the “File | Preferences | Settings” option. On macOS, navigate to Code | Preferences | Settings.
In the Search settings box, enter compact.
Clear the Explorer: Compact Folders checkbox, as shown in the figure:
Close the Settings tab.
Creating a Razor class library
Let’s create a new Razor class library:
Step 1: Use ...