asp.net - 打印友好的 ASP.NET MVC 3 View

标签 asp.net css asp.net-mvc-3 printing

我想创建我的 ASP.NET MVC 3 View 的打印友好版本,我该怎么做?另外,如果我需要制作 View 的几个部分的打印友好版本怎么办?

问候。

最佳答案

我使用相同的 View ,但有 2 个 CSS 文件(一个带有 media="screen",另一个带有 media"print")。

在打印 CSS 文件中,我使用 CSS 使用 display:none; 隐藏所有不相关的 DOM 元素。

示例 MVC View :

<html>
<head>
    <link rel="stylesheet" type="text/css" media="screen" href="screen.css" />
    <link rel="stylesheet" type="text/css" media="print" href="print.css" />
</head>
<body>
    <div id="pageHeader">This will not be shown in print - menubar, etc.</div>
    <h1>Title</h1>
    <p>Text</p>
</body>
</html>

示例 print.css 文件:

#pageHeader {
    display: none;
}

看看这篇关于打印 CSS 的好文章“A List Apart”:http://www.alistapart.com/articles/goingtoprint/

关于asp.net - 打印友好的 ASP.NET MVC 3 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5563772/

相关文章:

c# - WebClient DownloadFile - 访问被拒绝或找不到部分路径

css - 设置水平滚动条的长度

html - 如何使用 JSP 交替 HTML 表格行颜色?

asp.net-mvc-3 - ASP .Net MVC 3 HTTPContext 包装器

asp.net - 您如何将一个 asp.net 验证器绑定(bind)到多个控件?

c# - Log4net 配置问题

c++ - 如何使用 Visual Studio 2017 调试从 asp.net 调用的 native C++

html - Stock quote api,无法打印文本颜色

javascript - 如何从其 OnBegin 函数中引用已单击的 ActionLink `a` 元素?

html - 链接在 Firefox 中不起作用