Adding Blazor to an MVC/Razor pages site
When I started with Blazor this was exactly the scenario we wanted to address. We had an MVC/Razor pages mix and it was time for an upgrade.
We solved it by implementing Razor pages that referred to Razor components. Looking back at it now it was not a pretty solution, at least not for a while until we got to a point where most of the code was rewritten in Blazor.
The challenge is that if we navigate to a page that has a Blazor component (Razor component) that page is connected to the server, and established a WebSocket. If we navigate away from that page to an MVC page for example the script was reloaded and a new connection was established, leaving the old one on the server for 3 minutes.
We don’t have a lot of users and for us, that technique worked long enough for us to finish the migration and launch a new Blazor version of the site.
But I have some good news!
Using the same custom elements we can get this to run on a Razor Pages site...