Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

razor syntax: loop with ifs and divs

It's my first post, hence hello :)

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

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

    if (left)
    {            
        </div>
    }
}
like image 263
Mariusz.W Avatar asked Feb 03 '12 21:02

Mariusz.W


1 Answers

You need to use the escape character to let the razor engine know that <div> is text by using @:

code:

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

if (left)
{            
    @:</div>
}
}
like image 173
Travis J Avatar answered Sep 30 '22 16:09

Travis J