0
How to assemble a list using foreach to change the positioning of the image. If my Count is 1, position the image on the left side, if my Count is 2 position the image on the right side, follow my code.
<div class="container">
@foreach (var item in Model.DadosEmpresa)
{
    @if (Model.DadosEmpresa.Count == 1)
    {
        <section class="row align-items-center padding-bottom-2x">
            <div class="col-md-5"><img class="d-block w-270 m-auto" src="@item.Imagem" alt="Foto Empresa"></div>
            <div class="col-md-7 text-md-left text-center">
                <div class="mt-30 hidden-md-up"></div>
                <h2>@Html.Raw(item.Texto)</h2>
                <p class="text-sm">
                    @Html.Raw(item.TextoDestaque)
                </p>
            </div>
        </section>
    }
    @if (Model.DadosEmpresa.Count == 2)
    {
        <section class="row align-items-center padding-bottom-2x">
            <div class="col-md-7 text-md-left text-center">
                <div class="mt-30 hidden-md-up"></div>
                <h2>@Html.Raw(item.Texto)</h2>
                <p class="text-sm">
                    @Html.Raw(item.TextoDestaque)
                </p>
            </div>
            <div class="col-md-5"><img class="d-block w-270 m-auto" src="@item.Imagem" alt="Foto Empresa"></div>
        </section>
    }
    @if (Model.DadosEmpresa.Count == 3)
    {
        <section class="row align-items-center padding-bottom-2x">
            <div class="col-md-5"><img class="d-block w-270 m-auto" src="@item.Imagem" alt="Foto Empresa"></div>
            <div class="col-md-7 text-md-left text-center">
                <div class="mt-30 hidden-md-up"></div>
                <h2>@Html.Raw(item.Texto)</h2>
                <p class="text-sm">
                    @Html.Raw(item.TextoDestaque)
                </p>
            </div>
        </section>
    }
    @if (Model.DadosEmpresa.Count == 4)
    {
        <section class="row align-items-center padding-bottom-2x">
            <div class="col-md-7 text-md-left text-center">
                <div class="mt-30 hidden-md-up"></div>
                <h2>@Html.Raw(item.Texto)</h2>
                <p class="text-sm">
                    @Html.Raw(item.TextoDestaque)
                </p>
            </div>
            <div class="col-md-5"><img class="d-block w-270 m-auto" src="@item.Imagem" alt="Foto Empresa"></div>
        </section>
    }
}
						
It seems that two items are the same can already refactor this.
– novic