0

I'm trying to execute the following code in asp.net razor view-

@foreach (var contact in ViewBag.ContactInfo.Rows)
{
    if (columnCount>4)
    {
        <div class="row-fluid">
    }

    <div class="span4">@ViewBag.SomeText</div>

    //This if block is treated as normal text.
    if (columnCount > 4)
    {
        </div>
        columnCount = 0;
    }

    columnCount++;
}

But it gives parse error.

Any help?

s.k.paul
  • 7,099
  • 28
  • 93
  • 168

2 Answers2

1

Try something like below. As you are opening div tag in one if and closing in other, razor viewengine is somehow not able to parse it. Check here for more

      @foreach (var contact in ViewBag.ContactInfo.Rows)
        {
            if (columnCount>4)
            {
                <div class="row-fluid">
                <div class="span4">@ViewBag.SomeText</div>
                </div>
            }

            else
            {
                <div class="span4">@ViewBag.SomeText</div>
            }
            columnCount++;
        }
Community
  • 1
  • 1
Nitin Varpe
  • 10,450
  • 6
  • 36
  • 60
0
@foreach (var contact in ViewBag.ContactInfo.Rows)
{
    if (columnCount>4)
    {
       @:<div class="row-fluid">
    }

   <div class="span4">@ViewBag.SomeText</div>

   //This if block is treated as normal text.
   if (columnCount > 4)
   {
      @:</div>
      columnCount = 0;
   }

   columnCount++;

}

s.k.paul
  • 7,099
  • 28
  • 93
  • 168