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
What did the trick for me was pressing CTRL+Z after pasting, then the formatting is removed.