繁体   English   中英

动态生成的HTML表-如何限制宽度

[英]Dynamically generated HTML table - how to constrain width

我正在使用MVC3创建动态表。

但是该表不在布局中的页面上,并且不位于共享div内吗?

@{
    ViewBag.Title = "Users";
}

<h2>Users</h2>

<p>
    @Html.ActionLink("Create New User", "Create")
</p>


    <table>
        <tr>
            <th>
                UserID
            </th>
            <th>
                UserName
            </th>
            <th>
                UserForename
            </th>
            <th>
                PW
            </th>
            <th>
                UserTypeID
            </th>
            <th>
                PasswordMustBeChanged
            </th>
             <th></th>
        </tr>

    @foreach (var item in Model) {
        <tr>
            <td>
              @Html.DisplayFor(modelItem => item.U1_UserId)
            </td>
            <td>
                 @Html.DisplayFor(modelItem => item.U1_UserName)
            </td>
             <td>
               @Html.DisplayFor(modelItem => item.U1_UserForename)
            </td>
             <td>
               @Html.DisplayFor(modelItem => item.U1_PW)
            </td>
            <td>
                 @Html.DisplayFor(modelItem => item.U1_UserTypeID)
            </td>
             <td>
               @Html.DisplayFor(modelItem => item.U1_PasswordMustBeChanged)
            </td>
             <td>
                @Html.ActionLink("Edit", "Edit", new { id=item.U1_UserId }) |
                @Html.ActionLink("Delete", "Delete", new { id=item.U1_UserId })
            </td>       
        </tr>
    }

这是表格,它呈现在共享的layotu @renderbody中。 但是表不在div内。

只是在黑暗中开了一枪,但看来您的标头部分还多了一个<th></th> 那是故意的吗?

您可能会应用overflow: scroll; _Layout主要部分中的_Layout

<section id="main" style="overflow:scroll;">
    @RenderBody()
</section>

这样,如果表格的宽度大于主部分的大小,则会显示滚动条。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM