This has been asked before: Why doesn't Visual Studio code formatting work properly for Razor markup?
But that question is a couple years old. And Razor formatti
I do not have a .Net Core project nor Blazor. So unfortunately I cannot test this. But a new formatting engine has been released by Microsoft for these languages.
https://devblogs.microsoft.com/aspnet/new-experimental-razor-editor-for-visual-studio/
Requires the latest edition of Visual Studio 2019.