0

基本上我正在创建一个数据网格,它显示来自数据库中不同表的数据。我为此使用 ASP.NET MVC4。以下是我的部分代码的外观:

<table class="myTable">
    <tbody>
        @foreach (var item in Model.sets)
        {
            <tr class="parent" data-level="0">
                <td>
                      @item.setName
                @* Here my logic would go*@
                </td>
            </tr>
        }

因此,在显示集合名称的行之后,在下一列中,我想显示属于该集合的元素。所以我写了另一个 for 循环<td></td>,它将遍历Model.elements并检查它是否属于该集合并显示它.但我得到“元素td不能嵌套在元素td中”验证错误。那么如何将数据添加到下一列的行中呢?

4

1 回答 1

0

Put your logic below the first end td tags instead. You can't put td tags inside other td tags; a series of sibling td tags make up a row.

If you want each separate piece of data in its own column:

        @foreach (var item in Model.sets)
    {
        <tr class="parent" data-level="0">
            <td>
                  @item.setName
            </td>
            @foreach (var element in Model.elements)
            {
            <td>
                @*logic here*@
            </td>
            }
        </tr>

If you want all your content inside the same cell, then you want:

        @foreach (var item in Model.sets)
        {
            <tr class="parent" data-level="0">
                 <td>
                      @item.setName
                </td>
                <td>
                @foreach (var element in Model.elements)
                {
                    @*logic here*@               
                }
                </td>
            </tr>
        }
于 2013-08-05T13:41:08.393 回答