Visualization of a table in asp.net mvc html

0

Good, I have an index view generated automatically by the controller in C #, I need to show some photos in a table and every 4 columns a row is generated automatically, but I can not do it, it just shows me the run photos creating columns and now, I do not know how to put a limit of 4 columns and n rows each time you need it according to the number of photos in the Database Someone to help me

            @model IEnumerable<Domain.User>

            @{
                ViewBag.Title = "Index";
            }

            <h2>Users</h2>

            <p>
                @Html.ActionLink("Create New", "Create", new { }, new { @class = "btn btn-primary" })
            </p>
            <table class="table table-bordered table-hover" style="border-spacing:5px;">

            @foreach (var item in Model)
            {
                <tr>
                        @if (!string.IsNullOrEmpty(item.PhotoInterior1))
                        {
                            <img src="@Url.Content(item.PhotoInterior1)" alt="Image" style="width:200px;height:300px" />
                        }
                </tr>
            }
            </table>
    
asked by Sebastian Echeverry 30.06.2017 в 17:23
source

1 answer

1

I think you need something like:

@model IEnumerable<Domain.User>

@{
                ViewBag.Title = "Index";
}

<h2>Users</h2>

<p>
    @Html.ActionLink("Create New", "Create", new { }, new { @class = "btn btn-primary" })
</p>
<table class="table table-bordered table-hover" style="border-spacing:5px;">
    <tr>
        @{ var itemCount = 0;}
        @foreach (var item in Model)
            {
                if(itemCount > 4)
                {
                    Html.Raw("<tr>");
                }

                if (!string.IsNullOrEmpty(item.PhotoInterior1))
                {
                        <td style="width:154.8px; height:252px">
                            <img src="@Url.Content(item.PhotoInterior1)" alt="Image" style="width:200px;height:300px" />
                        </td>
                }
                if (itemCount > 4)
                {
                    Html.Raw("</tr>");
                    itemCount = 0;
                } else {
                    itemCount++;
                }
            }
        </tr>
    </table>
    
answered by 30.06.2017 в 18:09