How to format razor pages in blazor in visual studio 2022

Ante Gavranovic 10 Reputation points
2023-02-02T09:09:50.9866667+00:00

Hi,

we are having problems with formatting after upgrade to visual studio 2022. In visual studio 2019 we could format our razor files pretty well, in visual studio it looks really bad. We cannot use 2019 anymore because of the .net 7.

nikakonevalja

nevalja

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,402 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Zhi Lv - MSFT 32,021 Reputation points Microsoft Vendor
    2023-02-03T02:50:35.9766667+00:00

    Hi @Ante Gavranovic

    To format the code in the VS 2022, you can try to use the following methods:

    1. Format Entire Document.
      Hot Key: Ctrl+K, Ctrl+D
      Menu: Edit => Advanced => Format Document.
    2. Format select Document.
      Hot Key: Ctrl+K, Ctrl + F
      Menu: Edit => Advanced => Format Selection document.
    3. Use Tab key. Select the relate code, then click the Tab key.
    4. Use Spacebar key. Move the cursor before the attribute or elements, then click the Spacebar.

    Refer to the following screenshot:

    User's image


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,

    Dillion

    1 person found this answer helpful.