[Solved] How to list DB data like this in MVC4?


Without changing your data structure, you could simply do the following (assuming your Model doesn’t have a lot of items in it):

EDIT: As requested in comments, I’ve added it so each header row only contains 5 items:

<table>
    <tr>
        @for (int i = 0; i < Model.Count(); i++)
        {
            <th>@item.Id</th>
            @if ((i + 1) % 5 == 0)
            {
                @:</tr><tr>
            }
        }
    </tr>
    @foreach(var item in Model)
    {
        <tr>
            <td>@* some data on item *@</td>
        </tr>     
    }
</table>

2

solved How to list DB data like this in MVC4?