Created
October 27, 2017 08:08
-
-
Save ps-team/b276721e7dbcc0aa4264bb9b779ddea7 to your computer and use it in GitHub Desktop.
Conditionally change the class on items in a foreach loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@{ | |
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