Created
June 24, 2015 11:13
-
-
Save adamhopkinson/0ef7bfca02678f12a841 to your computer and use it in GitHub Desktop.
Breaking a list into chunks
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
// define how many items we want per chunk | |
var itemsPerChunk = 3; | |
// break the list of items into chunks | |
var chunks = items.Select((s, i) => new { Value = s, Index = i }).GroupBy(item => item.Index / itemsPerChunk, item => item.Value); | |
// iterate through each chunk | |
foreach (var chunk in chunks) | |
{ | |
<div class="row"> | |
// iterate through each item in the chunk | |
@foreach (var item in chunk) | |
{ | |
<div class="span4"> | |
@item.DisplayName | |
</div> | |
} | |
</div> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment