Visual Studio 2022 is having issues with html tags in "if" blocks on Razor (chtml) pages

Viewed 148

When adding something like a div tag inside an if-block nested in div tag, Visual Studio will not finish the closing div tag. Worse yet, when I type "</div>" it will create another "<div>" in front of it.

The problem appears to be that it does not detect the opening div tag before the if-block and thinks the closing tag after the if-block is for that inner div. However, selecting the tags highlight the corresponding beginning or end tag.

Here is an example.

<div>
@if (condition)
{
    <div>
     THE FOLLOWING CLOSING TAG IS WHAT WILL NOT APPEAR.
    </div>          
}
</div>

How do I fix this?

0 Answers
Related