diff --git a/Francesco.Recipes.World/Views/Shared/_RecipeInstructionGridPartial.cshtml b/Francesco.Recipes.World/Views/Shared/_RecipeInstructionGridPartial.cshtml index 2a7b44b..ed4f682 100644 --- a/Francesco.Recipes.World/Views/Shared/_RecipeInstructionGridPartial.cshtml +++ b/Francesco.Recipes.World/Views/Shared/_RecipeInstructionGridPartial.cshtml @@ -6,12 +6,16 @@
@{ var groupedInstructions = Model.Instructions.OrderBy(i => i.Number).ToList(); - var rows = (int)Math.Ceiling(groupedInstructions.Count / 3.0); + var instructionRows = groupedInstructions + .Select((instruction, index) => new { Instruction = instruction, Index = index }) + .GroupBy(x => x.Index / 3) + .Select(g => g.Select(x => x.Instruction).ToList()) + .ToList(); - for (int row = 0; row < rows; row++) + foreach (var row in instructionRows) {
- @for (int col = 0; col < 3 && (row * 3 + col < groupedInstructions.Count); col++) + @for (var instruction in row) { var instruction = groupedInstructions[row * 3 + col];