I want to display 3 Cells in a row and then create row <tr> dynamically for remaining cells. When I searched for this logic, I am getting same answer from multiple articles about using modulo and it seems working for evryone but I'm not getting desired output. What am I missing here?

Code:

<table>
    @for (var i = 0; i < deliveryProvider.DeliveryTagInfo.DeliveryProviderTagList.Count; i++)
    {
        var deliveryTag = deliveryProvider.DeliveryTagInfo.DeliveryProviderTagList[i];

        if ((i%3) == 0) //Create new row for 4th item 
        {
            @:<tr>
        }
        <td>
            <div class="input-element checkbox">
                @Html.CheckBoxFor(x => x.DeliveryProviderList[j].DeliveryTagInfo.IsDeliveryTagSelectedList[i], new
                {
                    name = deliveryTag,
                    id = deliveryTag
                })
                <label for="@deliveryTag">
                    <span></span>@deliveryTag</label>
            </div>
        </td>
        if ((i%3) == 0)
        {
            @:</tr>
        }
    }
</table>

Output:

enter image description here

Expected Output:

Test1

ALCOHOL   SPILLABLE    COLD_BAG

HOT_BAG    HEAVY       SIZE

Test2

abc  pqr  xyz

Related posts

Recent Viewed