Razor Components (Server-Side Blazor) Refined in ASP.NET Core Preview

ASP.NET Core's Razor Components -- aka server-side Blazor -- received a lot of attention in the just-released NET Core 3.0 Preview 3 as Microsoft continues to mature its initiative to run C# code in the browser instead of just JavaScript.

Or, as Microsoft said in an announcement yesterday, Razor Components, introduced in an earlier preview, provide "a new way to build interactive client-side Web UI with ASP.NET Core."

While the experimental Blazor project started off as more of a full-stack approach with client-side and server-side components, the client-side effort ran into problems in getting C# to play nice on the Web with WebAssembly, yet another experimental project that facilitates the development of Web apps with C# and other higher-level languages.

As the client-side team continues to work on those problems, the server-side effort was dubbed Razor Components and moved to be an integral part of ASP.NET Core.

In the new Preview 3, Razor Components received many improvements, described by Microsoft as:

  • Single project template: The Razor Components project template is now a single project instead of two projects in the same solution.
  • New .razor extension: To clarify which Razor files should be compiled as Razor Components, Microsoft introduced a new file extension: .razor.
  • Endpoint routing integration: Razor Components are now integrated into ASP.NET Core's new Endpoint Routing system.
  • Prerendering: The Razor Components project template now does server-side prerendering by default, so when a user navigates to an application, the server will perform an initial render of Razor Components and deliver the result to their browser as plain static HTML. Then, the browser will reconnect to the server via SignalR and switch the Razor Components into a fully interactive mode.
  • Razor Components in Razor Class Libraries: Developers can now add Razor Components to Razor Class Libraries and reference them from ASP.NET Core projects using Razor Components.
  • Improved event handling: The new EventCallback and EventCallback<> types make defining component callbacks much more straightforward.
  • Forms and validation: This preview release adds built-in components and infrastructure for handling forms and validation.

Regarding the ability to add Razor Components to Razor Class Libraries and reference them from ASP.NET Core projects using Razor Components, Microsoft added one caveat: "Note that Razor Class Libraries are not compatible with Blazor apps in this release. Also, Razor Class Libraries do not yet support static assets. To create components in a library that can be shared with Blazor and Razor Components apps you still need to use a Blazor Class Library. This is something we expect to address in a future update."

Features other than Razor Components also received their share of improvements, including:

  • Runtime compilation
  • Worker Service template
  • gRPC template
  • Angular template updated to Angular 7
  • Authentication for Single Page Applications
  • SignalR integration with endpoint routing
  • SignalR Java client support for long polling

All of the above are explained in detail in the release notes.

In announcing .NET Core 3.0 Preview 3, Microsoft announced that .NET Core 3.0 would not be shipping with Visual Studio 2019 when it's released on April 2. Rather, it will ship in the second half of the year, with the exact date to announced during Microsoft's Build conference in early May.

About the Author

David Ramel is an editor and writer for Converge360.

comments powered by Disqus


  • AI for GitHub Collaboration? Maybe Not So Much

    No doubt GitHub Copilot has been a boon for developers, but AI might not be the best tool for collaboration, according to developers weighing in on a recent social media post from the GitHub team.

  • Visual Studio 2022 Getting VS Code 'Command Palette' Equivalent

    As any Visual Studio Code user knows, the editor's command palette is a powerful tool for getting things done quickly, without having to navigate through menus and dialogs. Now, we learn how an equivalent is coming for Microsoft's flagship Visual Studio IDE, invoked by the same familiar Ctrl+Shift+P keyboard shortcut.

  • .NET 9 Preview 3: 'I've Been Waiting 9 Years for This API!'

    Microsoft's third preview of .NET 9 sees a lot of minor tweaks and fixes with no earth-shaking new functionality, but little things can be important to individual developers.

  • Data Anomaly Detection Using a Neural Autoencoder with C#

    Dr. James McCaffrey of Microsoft Research tackles the process of examining a set of source data to find data items that are different in some way from the majority of the source items.

  • What's New for Python, Java in Visual Studio Code

    Microsoft announced March 2024 updates to its Python and Java extensions for Visual Studio Code, the open source-based, cross-platform code editor that has repeatedly been named the No. 1 tool in major development surveys.

Subscribe on YouTube