我遇到了同样的问题,似乎你不能在你的 html 内容中使用传统使用的 css ......只有一些内联样式设置有效..这是我为在生成的表格中获得一些样式所做的示例...... .
顺便说一句,我的 Layout 设置为 null (Layout = null) 否则它不会工作......我这样做是因为我不知道用语法制作表格
<itext creationdate="@DateTime.Now.ToString()" producer="RazorPDF">
<table>
<tr>
<th align="center">@Model.CampaignName</th>
</tr>
</table>
<h4>@ViewBag.CampaignName</h4>
<table border="1" cellpadding="3">
<thead>
<tr>
<td colspan="5" align="center">
<strong>Delivery List</strong>
</td>
</tr>
<tr>
<th>@Html.DisplayNameFor(m => m.DeliveryList.FirstOrDefault().ShopName)</th>
<th width="35%">@Html.DisplayNameFor(m => m.DeliveryList.FirstOrDefault().MediaTypeName)</th>
<th>@Html.DisplayNameFor(m => m.DeliveryList.FirstOrDefault().Count)</th>
<th>@Html.DisplayNameFor(m => m.DeliveryList.FirstOrDefault().Width)</th>
<th>@Html.DisplayNameFor(m => m.DeliveryList.FirstOrDefault().Height)</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.DeliveryList)
{
<tr>
<th>@Html.DisplayFor(m => item.ShopName) - @item.ShopAddress</th>
<td>@Html.DisplayFor(m => item.MediaTypeName)</td>
<th>@Html.DisplayFor(m => item.Count)</th>
<td>@Html.DisplayFor(m => item.Width)</td>
<td>@Html.DisplayFor(m => item.Height)</td>
</tr>
}
</tbody>
</table>
<br />
<table border="1" cellpadding="3">
<thead>
<tr>
<td colspan="5" align="center">
<strong>Production List</strong>
</td>
</tr>
<tr>
<th>@Html.DisplayNameFor(m => m.ProductionList.FirstOrDefault().MediaTypeName)</th>
<th width="45%">@Html.DisplayNameFor(m => m.ProductionList.FirstOrDefault().Comments)</th>
<th>@Html.DisplayNameFor(m => m.ProductionList.FirstOrDefault().CountAll)</th>
<th>@Html.DisplayNameFor(m => m.ProductionList.FirstOrDefault().Width)</th>
<th>@Html.DisplayNameFor(m => m.ProductionList.FirstOrDefault().Height)</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.ProductionList)
{
<tr>
<td>@Html.DisplayFor(m => item.MediaTypeName)</td>
<th width="30%">@Html.DisplayFor(m => item.Comments)</th>
<th>@Html.DisplayFor(m => item.CountAll)</th>
<th>@Html.DisplayFor(m => item.Width)</th>
<th>@Html.DisplayFor(m => item.Height)</th>
</tr>
}
</tbody>
</table>
</itext>