I have a view where I conditionally iterate and print items: SPANs are not displayed (as expected).

<div>
@if (Model.SomeCondition)
{
    @foreach (var x in Model.SomeData)
    {
        <span>@x.Title</span>
    }
}
</div>

Now I'd like not to display the enclosing DIV, however it doesn't work: SPANs are still not displayed, but the DIV is. Why does this happen?

@if (Model.SomeCondition)
{
<div>
    @foreach (var x in Model.SomeData)
    {
        <span>@x.Title</span>
    }
</div>
}

Related posts

Recent Viewed