Combining MVC + Blazor in the same project

According to ASP.NET Core 3.0 Preview 2 release notes

Currently you cannot use Blazor directly with ASP.NET Core MVC but you can use with newly introduced Razor Component. Microsoft is expecting using Blazor directly with ASP.NET Core MVC will be possible in the upcoming versions of ASP.MET Core.

For more details: ASP.NET Core updates in .NET Core 3.0 Preview 2

This is definitely now possible for server-side Blazor, Chris Sainty's blog (and the source for the example in that blog) gives an example of exactly how to do that.

Personally I prefer to have the Blazor components in a separate project in the same solution as the MVC project. There are a few reasons for that:

  • I find Blazor projects are faster to start up than MVC
  • I've only managed to make the automatic rebuilding of the project (basic hot reload) work in a Blazor project, not in an MVC project
  • I've found it useful to be able to isolate the Blazor components to be sure that issues aren't related to the MVC parts of a page.

I tend to do the initial debugging with the Blazor project set as the startup project and then switch to the MVC project when I'm ready to integrate the component into an MVC page.

If you want to try that approach, my answer to the question Adding Server-Side Blazor to an existing MVC Core app gives a complete walk through of how to add a separate Blazor project to an existing solution that contains an MVC project, and then how to use those Blazor components in the MVC project.

I expect very similar approaches would apply for client-side Blazor too, but I haven't tried that yet.