C# 在 ASP.NET MVC 4 中提供打印功能

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17544371/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 09:48:05  来源:igfitidea点击:

Provide Print functionality in ASP.NET MVC 4

c#asp.net-mvc-4

提问by Rohaan

I am having a view with HTML tables filled with information that I want to print in ASP.NET MVC 4 and C#.

我有一个 HTML 表的视图,其中包含我想在 ASP.NET MVC 4 和 C# 中打印的信息。

I don't know the actual code that prints the document.

我不知道打印文档的实际代码。

any help will be appreciated

任何帮助将不胜感激

采纳答案by Ryan McDonough

Well you have two choices

那么你有两个选择

  1. Either use JS

    <a href="javascript:window.print()">Click to Print This Page</a>

  2. Or print to a PDF using Action Result in MVC

  1. 要么使用JS

    <a href="javascript:window.print()">Click to Print This Page</a>

  2. 或使用 MVC 中的 Action Result 打印为 PDF

For the JS option you will want to build a print cssfile so as to best render the page during printing, also hide some element that you don't need to appear - menus for example.

对于 JS 选项,您需要构建一个打印 css文件,以便在打印期间最好地呈现页面,同时隐藏一些您不需要出现的元素 - 例如菜单。