我尝试下面的代码打破页面,而打印但它不起作用,我了解到分页符不能在嵌套的div标签中工作,我不知道如何实现这一点,基本上我试图显示图像,所以根据屏幕的显示尺寸连续存在4个或更多,但是在打印时它应该连续打印4个图像,接下来的4个图像应该打印在下一页,就像现在打印时一样图像和内容被切断,请帮忙
<div class='row small'> @foreach (var item in Model.BuyerList.ImageList) { <div class="card bg-light mb-3 mr-1 card-text-fixed-width" style='page-break-after:always'> <div class="img-control"> @if (!string.IsNullOrWhiteSpace(item.ImageUrl)) { <img src="@item.ImageUrl" style="height:150px;" class="card-img-top" alt="Card image" /> } else { <img src="~/AdTrack Images/NoProductImage.png" style="height:150px;" class="card-img-top" alt="Card image" /> } <div class="edit d-print-none"> <a data-toggle="modal" data-id='{"id": "@item.Items.Number","ItemId":"@item.Items.ItemId","AdId":"@item.Header.Id"}' class="open-AddBookDialog btn btn-primary" href="#"><i class="fa fa-pencil fa-lg"></i></a> </div> <div class="delete d-print-none"> <a data-toggle="modal" data-id='{"id": "@item.Items.Number","ItemId":"@item.Items.Id","AdId":"@item.Id"}' class="open-delete btn btn-primary" href="#"> <i class="fa fa-trash" style="font-size:15px;color:red" id="delete" name="delete"></i> </a> </div> <div class="edit d-print-none"> <a data-toggle="modal" data-id='{"id": "@item.Items.Number","AdId":"@item.Header.Id"}' class="open-AddBookDialog btn btn-primary" href="#"><i class="fa fa-info-circle fa-lg"></i></a> </div> } </div> <div class="card-header"> <div class="font-weight-bold">Page @Html.DisplayFor(modelItem => item.Number)- @Html.DisplayFor(modelItem => item.Business)</div> <div class="row mb-2 font-weight-bold"> <div class="col-md-6">Cut: @Html.DisplayFor(modelItem => item.Items.Number)</div> <div class="col-md-6 text-right">9-Box: @Html.DisplayFor(modelItem => item.Items.BoxNumber)</div> </div> <div class="row mb-2 font-weight-bold"> <div class="col-md-4">Group @Html.DisplayFor(modelItem => item.Department.Test)</div> @*<div class="col-md-4">Div: @Html.DisplayFor(modelItem => item.Department.Division)</div>*@ <div class="col-md-4">Buyer @Html.DisplayFor(modelItem => item.Department.Test)</div> <div class="col-md-4">Dept @Html.DisplayFor(modelItem => item.Items.Department)</div> </div> </div> </div> } </div>
解决方法
使用style =’page-break-after:always’添加wrap div.
<div class='row small'> @foreach (var item in Model.BuyerList.ImageList) { <div style='page-break-after:always'> <div class="card bg-light mb-3 mr-1 card-text-fixed-width" > <div class="img-control"> @if (!string.IsNullOrWhiteSpace(item.ImageUrl)) { <img src="@item.ImageUrl" style="height:150px;" class="card-img-top" alt="Card image" /> } else { <img src="~/AdTrack Images/NoProductImage.png" style="height:150px;" class="card-img-top" alt="Card image" /> } <div class="edit d-print-none"> <a data-toggle="modal" data-id='{"id": "@item.Items.Number","AdId":"@item.Header.Id"}' class="open-AddBookDialog btn btn-primary" href="#"><i class="fa fa-pencil fa-lg"></i></a> </div> <div class="delete d-print-none"> <a data-toggle="modal" data-id='{"id": "@item.Items.Number","AdId":"@item.Id"}' class="open-delete btn btn-primary" href="#"> <i class="fa fa-trash" style="font-size:15px;color:red" id="delete" name="delete"></i> </a> </div> <div class="edit d-print-none"> <a data-toggle="modal" data-id='{"id": "@item.Items.Number","AdId":"@item.Header.Id"}' class="open-AddBookDialog btn btn-primary" href="#"><i class="fa fa-info-circle fa-lg"></i></a> </div> } </div> <div class="card-header"> <div class="font-weight-bold">Page @Html.DisplayFor(modelItem => item.Number)- @Html.DisplayFor(modelItem => item.Business)</div> <div class="row mb-2 font-weight-bold"> <div class="col-md-6">Cut: @Html.DisplayFor(modelItem => item.Items.Number)</div> <div class="col-md-6 text-right">9-Box: @Html.DisplayFor(modelItem => item.Items.BoxNumber)</div> </div> <div class="row mb-2 font-weight-bold"> <div class="col-md-4">Group @Html.DisplayFor(modelItem => item.Department.Test)</div> @*<div class="col-md-4">Div: @Html.DisplayFor(modelItem => item.Department.Division)</div>*@ <div class="col-md-4">Buyer @Html.DisplayFor(modelItem => item.Department.Test)</div> <div class="col-md-4">Dept @Html.DisplayFor(modelItem => item.Items.Department)</div> </div> </div> </div> </div> } </div>