Wrong Razor Formatting with Visual Studio 2022 and 2026
This issue has been moved from a ticket on Developer Community.
[severity:It's more difficult to complete my work] Please find attached a full solution with basically two Razor pages (tried to make the smallest possible example) where the document formating for Razor pages fail either partially or completly.
- Pages/NotFormatting.cshtml => fails completly and it's due to the inclusion within an onclick handler. Yet once compiled it works.
- Pages/TabsContinueToGrow.cshtml => every time the document is formatted a new tab on line 13 is added. This happens only if the code is within a block.
Both page compiles and work as expected. Therefore fully valid Razor page but the code editor is not able to handle them correctly.
Please correct the bug at least in 2026 as this is really a huge burden.
Original Comments
Feedback Bot on 11/09/2025, 04:26 PM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
NoFormatting.cshtml:
<a href="#" onclick="return confirm('@Localizer["Are you sure you want to delete this bill?"]');">@Localizer["Delete"]</a/>
The formatting operation is being aborted because it's trying to remove the last / in the invalid </a/> tag, but we've lost the log message that used to accompany that.
TabsContinueToGrow.cshtml:
@if (true)
{
@(Html.Grid()
.Render())
}
The formatter can't handle multi-line implicit expressions inside code blocks.
- We format multiline implicit expressions that aren't nested correctly
- We don't format multiline implicit expressions if they're nested in C# correctly
- We format multiline implicit expressions if they're nested in Html correctly
I can fix 2 really easily, but the fix breaks 3 🤦♂️
I think this might need us to commit to https://github.com/dotnet/razor/issues/11916 which would put it outside the scope of preview 2.