Razor Syntax: loop with ifs and divs

This is my first post, hello from here :)

I want to conditionally open and close a div. What am I doing wrong?

@foreach (var m in Model.Recipes)
{
    if (left)
    {
        <div class="rec-line">
    }    

    if (left)
    {            
        </div>
    }
}
+5
source share
1 answer

You need to use an escape character so that the razor engine knows that text <div>is text using@:

the code:

@foreach (var m in Model.Recipes)
{
if (left)
{
    @:<div class="rec-line">
}    

if (left)
{            
    @:</div>
}
}
+5
source

All Articles