Razor syntax formatting: Indentation level of control structures at the top level of a document
When writing a control structure like @if at the top level of a document, auto formatting applies the wrong indentation:
@if (true)
{
<div>
<p>
<span>...</span>
<p>
</div>
<div>
<span>...</span>
</div>
}
Everything following the first element in the block gets one indentation level less than expected until the closing tag of that element. Then we are back at the correct indentation level, but opening another element after that will bring back the same incorrect behavior.
However, this applies only to the top level. Wrapping the whole structure inside another element gives the expected behavior:
<div>
@if (true)
{
<div>
<span>...</span>
</div>
}
</div>
@NormanM123 Thanks for the report, unfortunately I'm unable to reproduce this:
A couple of questions:
- What version of Visual Studio are you using?
- How are you formatting this? Format Document? or does it format during typing?
- Does the issue repro for you with the exact code snippet in your report? I'm wondering if there is something you've redacted that might actually be the cause.
Any other info you can think of would be very useful! Thanks.
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 7 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.
Please see our Issue Management Policies for more information.