如何隐藏asp.net mvc项目中的打印页面?

时间:2017-07-09 00:41:07

标签: asp.net-mvc printing hide

我有一张包含很多td的表格。当我点击打印按钮时,我想在浏览器中隐藏其中一个打印页面。怎么做? 这是索引页面代码:

<div id="div_print"><table class="table table-bordered">
<tr class="info">
    <th dir="rtl">
        @Html.DisplayNameFor(model => model.a)
    </th>
    <th dir="rtl">
        @Html.DisplayNameFor(model => model.b)
    </th>
    <th dir="rtl">
        @Html.DisplayNameFor(model => model.c)
    </th>
        </tr>
      </div>
       @foreach (var item in Model) {
      <tr>
      <td>
        @{
        ViewData["class"]= "text-uppercase";
        }
        @Html.DisplayFor(modelItem => item.a)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.b)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.c)
    </td>
       <td>
        @Html.ActionLink("Edit", "Edit", new { id=item.z}, new { @class = "btn btn-primary" }) |
        @Html.ActionLink("Details", "Details", new { id=item.z}, new { @class = "btn btn-primary" }) |
        @Html.ActionLink("Delete", "Delete", new { id=item.z}, new { @class = "btn btn-warning" })
    </td>
</tr>
  }
  </table>

我想隐藏这一部分:

            <td>
                @Html.ActionLink("Edit", "Edit", new { id=item.z}, new { @class = "btn btn-primary" }) |
                @Html.ActionLink("Details", "Details", new { id=item.z}, new { @class = "btn btn-primary" }) |
                @Html.ActionLink("Delete", "Delete", new { id=item.z}, new { @class = "btn btn-warning" })
            </td>

1 个答案:

答案 0 :(得分:0)

使用CSS执行此操作:

@media print
{    
    .not-printable, .not-printable *
    {
        display: none !important;
    }
}

然后将not-printable添加到您不想打印的元素:

<div class="not-printable"></div>

CSS 3 Media Queries