0

I have a script like below on my View:

@{int count = 0;}
@foreach (var item in Model)
{
    <div >
        <div class="col-md-4"><img src="@item.ImageLink" />           
        @(count = count +1 );           
        @if(count ==3)
        {
            @(count = 0);
            @Html.Raw("<div class=\"clearfix visible-md\"></div>");
        }
       </div>
    </div>
}

The problem here is : in addition to the imageLink, the output also contain the value of count when it is assigned with value (meaning that it will print some number: 1,2,3,0 - which is value of count in each loop)

How can I resolve it?

Thanks & regards,

1 Answer 1

1

If you use parentheses it's output will be submitted as part of the HTML. You can use curly braces for code block as below.

@{
    int count = 0;
    foreach (var item in Model)
    {
    <div>
        <div class="col-md-4">
            <img src="@item.ImageLink" />
            @{count = count + 1;}
            @if (count == 3)
            {
                count = 0;
                @Html.Raw("<div class=\"clearfix visible-md\"></div>");
            }
        </div>
    </div>
    }
}
0

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.