gpt4 book ai didi

c# - 如何在 .CSHTML 中自动调整列宽?

转载 作者:太空宇宙 更新时间:2023-11-03 21:33:51 24 4
gpt4 key购买 nike

因此在 MVC 中,我使用 VS2013 的强大功能自动生成列表类型的 View ,该 View 使用 foreach 以数组格式显示对象列表及其属性。如何修改代码以自动调整列宽以适应?

<table class="table">
<tr>
<th align="center">
@Html.DisplayNameFor(model => model.IsoCode)
</th>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th align="center">
@Html.DisplayNameFor(model => model.Continent)
</th>
<th align="center">
@Html.DisplayNameFor(model => model.CountryId)
</th>
<th align="center">
@Html.DisplayNameFor(model => model.TotalLanguages)
</th>
<th></th>
</tr>

@foreach (var item in Model) {
<tr>
<td align ="center">
@Html.DisplayFor(modelItem => item.IsoCode)
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td align ="center">
@Html.DisplayFor(modelItem => item.Continent)
</td>
<td align ="center">
@Html.DisplayFor(modelItem => item.CountryId)
</td>
<td align ="center">
@Html.DisplayFor(modelItem => item.TotalLanguages)
</td>
<td>
@*@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |*@
@Html.ActionLink("Details", "Details", new { id = item.CountryId })
@*@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })*@
</td>
</tr>
}

最佳答案

首先,确保有足够的空间来显示表格单元格中的所有内容。如果您为表格指定了明确的宽度(例如,使用像素作为测量单位),您可能会无意中限制了表格呈现其内容所允许的空间。这是您可以尝试的方法

  • 如果为表格或单元格设置了明确的宽度,则将其删除或使用动态单位(例如百分比)
  • 为表格单元格设置white-space nowrap

试一试,看看效果如何

关于c# - 如何在 .CSHTML 中自动调整列宽?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22842679/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com