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?

3
  • Which error you are getting? Commented Jan 7, 2016 at 7:31
  • @ramiramilu Last if block is treated as normal text. Commented Jan 7, 2016 at 7:32
  • There is unclosed html tag in you razor condition . Please see this. Commented Jan 7, 2016 at 7:47

2 Answers 2

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++;
        }
Sign up to request clarification or add additional context in comments.

1 Comment

Then first if block says -'} missing'.
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++;

}

1 Comment

why the @:, what is it used for

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.