How to make Table with two foreach close <tr> </tr> Asp.Net MVC

Asked

Viewed 385 times

0

I need to make a table that for each row I have the information as shown below inserir a descrição da imagem aqui

See that in Lot 1 until City the data does not repeat at each foreach and only from the column Species the data repeats, in this row the foreach makes the looping 3 times and the columns Lot until City suffers a rowspan

Below code that is not working accordingly.

    @model GerenciamentoDeQuartos.Models.LoteViewModel
@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<p>
    @Html.ActionLink("Adicionar Lote", "NewLot")
</p>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Lote.NumeroLote)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Proprietario.Nome)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Propriedade.Nome)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Cidade.Nome)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.GetTipoGenero.Nome)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.GetGenero.QuantidadeAnimais)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.GetGenero.SequenciaInicial)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.GetGenero.SequenciaFinal)
        </th>
    </tr>


    @foreach (var item in Model.LoteList)
    {
        var rowSpanTable = item.LoteGenero.Count() <= 1 ? 0 : item.LoteGenero.Count();
        var imprimeSomentePrimeiraLinha = false;

        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.NumeroLote)
            </td>

            @foreach (var itemLoteGenero in item.LoteGenero)
            {

                if (!imprimeSomentePrimeiraLinha)
                {
                    <td>
                        @Html.DisplayFor(modelItem => item.Proprietario.Nome)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Propriedade.Nome)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Propriedade.Cidade.Nome)
                    </td>
                }

                <td>
                    @Html.DisplayFor(modelItem => itemLoteGenero.Genero.TipoGenero.Nome)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => itemLoteGenero.Genero.QuantidadeAnimais)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => itemLoteGenero.Genero.SequenciaInicial)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => itemLoteGenero.Genero.SequenciaFinal)
                </td>

                imprimeSomentePrimeiraLinha = true;
            }

        </tr>
    }
</table>
  • What would be the expected result?

  • The rowspan is supposed to be applied to which columns ?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.