如何将列表分为两列中的12个项目和6个项目?

时间:2018-04-23 12:07:46

标签: c# html asp.net-mvc razor

I have a list with 12 rows and I want to divide these rows in 2 columns, the first one with 6 rows and the second one with another 6 rows, someone can help me?

<div class="collapse" id="divRows-@item.BandeiraAdministradoraId">
                                                @foreach (var taxa in item.TaxaBandeiraAdministradoras)
                                                {
                                                    <div style="padding-left: 100px;">
                                                        @Html.DisplayFor(modelItem => taxa.NumeroTaxas, new { @class = "text-uppercase" })
                                                        @Html.Raw("X =")
                                                        @Html.DisplayFor(modelItem => taxa.ValorTaxa, new { @class = "text-uppercase" })
                                                        @Html.Raw("%")
                                                        <br />
                                                    </div>

                                                }
                                            </div>

2 个答案:

答案 0 :(得分:0)

您只需在您的ID中添加数字即可使其唯一,或根据您的某些模型数据制作此ID:

 @{int i = 0;}
 @foreach(var myItem in Model.Members)
 {
     <span id="name_@(i)">test</span>
     i++;
 }

答案 1 :(得分:0)

for-each替换为经典for-loop并使用其索引器。

//... some code
else
{
    for (int i = 1; i <= item.TaxaBandeiraAdministradoras.Count; i++)
    {
        var taxa = item.TaxaBandeiraAdministradoras[i];
        <div id="@(i.ToString())">Example Div with Id @(i.ToString()) from Loop</div>

        <div style="padding-left: 100px;" id="demo-@item.BandeiraAdministradoraId" class="collapse">
            <div style="float: left;">
                @Html.DisplayFor(modelItem => taxa.NumeroTaxas, new {@class = "text-uppercase"})
                @Html.Raw("X =")
            </div>

            <div style="float: left">
                @Html.Raw("&nbsp")
                @Html.DisplayFor(modelItem => taxa.ValorTaxa, new {@class = "text-uppercase"})
                @Html.Raw("%")
            </div>
        </div>
        <br/>
    }
}