Skip to content

Instantly share code, notes, and snippets.

@ps-team
Created October 27, 2017 08:08
Show Gist options
  • Save ps-team/b276721e7dbcc0aa4264bb9b779ddea7 to your computer and use it in GitHub Desktop.
Save ps-team/b276721e7dbcc0aa4264bb9b779ddea7 to your computer and use it in GitHub Desktop.
Conditionally change the class on items in a foreach loop
@{
int counter=0;
}
@foreach (var item in Model)
{
counter++;
<div class="@(counter<=3 ? "classRed":"classBlue")">
<img src="@item.Blog.Image.img_path" alt="Not Found" />
//other markup also here
</div>
if (counter == 6)
{
counter = 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment