rss
TIP : Blazor Unexpected closing tag ‘div’ with no matching start tag. - Blog of Christophe Peugnet
20 June 2021

TIP : Blazor Unexpected closing tag ‘div’ with no matching start tag.

forum
jobs
languagenews

Quick Monday morning tip. In a loop, I needed to open a <Div> and close that block after several elements in the loop. However Razor does not seem to be able to understand the C# conditions during its code analysis.

@foreach (var item in myObjects)
    if (myCondition)
    {
        <Div>
    }
    else
    {
        </Div>
    }

    // ...
}

Well, we can’t compile the code. We get this error “ RZ9981 Unexpected closing tag ‘div’ with no matching start tag.

The little trick is to use either

@((MarkupString)"<div>")

or

@:</div>

Leave a Reply

jobs
language news