Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在.CSHTML中自动调整列宽?_C#_Html_Asp.net Mvc_Razor_Visual Studio 2013 - Fatal编程技术网

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

C# 如何在.CSHTML中自动调整列宽?,c#,html,asp.net-mvc,razor,visual-studio-2013,C#,Html,Asp.net Mvc,Razor,Visual Studio 2013,因此,在MVC中,我使用VS2013的强大功能自动生成一个列表类型的视图,该列表类型使用foreach以数组格式显示对象列表及其属性。如何修改代码以自动调整列宽以适应需要 <table class="table"> <tr> <th align="center"> @Html.DisplayNameFor(model => model.IsoCode) </th>

因此,在MVC中,我使用VS2013的强大功能自动生成一个列表类型的视图,该列表类型使用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>
}

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

如果为表格或单元格设置了显式宽度,则将其删除或使用动态单位(如百分比) 为表格单元格设置空白nowrap
试一试,看看效果如何首先,确保有足够的空间显示表格单元格中的所有内容。如果为表格指定明确的宽度,例如使用像素作为测量单位,则可能会无意中限制表格呈现其内容所允许的空间。这是你可以尝试的

如果为表格或单元格设置了显式宽度,则将其删除或使用动态单位(如百分比) 为表格单元格设置空白nowrap
试一试,看看它是如何运行的

使用T4,您可以在生成过程中这样做。如果我理解的很好。自动调整列的大小以适应什么?表格单元格的内容使用T4可以在生成过程中执行此操作。如果我理解得很好的话。自动调整列的大小以适应什么?我尝试了表格Cells的内容:@Html.DisplayFormodelItem=>item.Name,但它没有自动调整大小以使其变小,必须进入引导并注释掉宽度:100%;排队。这张桌子对我也很有用@Html.DisplayFormodelItem=>item.Name我尝试了:@Html.DisplayFormodelItem=>item.Name,但它没有自动调整大小使其变小,必须进入引导并注释掉宽度:100%;排队。这张桌子对我也很有用@Html.DisplayFormodelItem=>item.Name