【发布时间】:2012-11-17 18:01:42
【问题描述】:
作为给定项目列表中我当前任务的一部分,用户可以选择其中的一些并调用“打印”不选择的项目。
对于每个选定的项目,我们需要打印详细信息。这类似于在销售系统中打印选定项目的发票。
我已经创建了一个局部视图来编写每条记录的详细信息,但我不确定如何按照我的要求使用它。
我可以在 document.ready 上调用 jQuery print 来实现我的要求吗?
正如@Levib 建议的那样,在我的 PrintView 中调用局部视图。而PrintView的document.reay函数正在调用window.print。但是当我尝试调用“打印”时,我看不到打印对话框。
这是我的看法,
@section Styles
{
<link rel="stylesheet" href="AdminStyle.css" type="text/css" media="all" />
<link rel="stylesheet" href="AdminPrintOrder.css" type="text/css" media="print" />
}
@foreach (var item in Model)
{
<div id="content" style="page-break-before: always">
@{Html.RenderPartial("_OrderDetailView", item);}
</div>
}
@section scripts
{
<script type="text/javascript">
$(document).ready(function () {
debugger;
window.print();
});
</script>
}
我的打印调用者视图是
function printInvoices(){
$.ajax({
type: 'POST',
url: '/Batch/PrintInvoices',
data: '{ "allocationId" : "' + unSelected.toString() + '"}',
contentType: "application/json; charset=utf-8",
traditional: true,
success: printedView,
error: errorInSubscribing
});
}
我是否需要处理 ajax reposne 来填充打印对话框。
function printedView() {
unSelected = [];
}
控制器动作是
[HttpPost]
public ActionResult PrintInvoices(string allocationId)
{
var context = new BatchContext();
var orderDetails = context.GetOrderDetails(RetriveList(allocationId));
return View(orderDetails);
}
【问题讨论】:
-
我不认为有“jQuery print”,但总是有
window.print(),与新窗口或 iframe 一起使用可以打印页面的一部分,但有一些交叉- 浏览器问题。 -
我认为 'printElement' 来自 jQuery。
-
这可能是一个用jQuery编写的插件,在后台使用window.print()。你应该在你的问题中概述这样的细节,
-
好的..如果我调用 window.print 它将处理多个文档。我需要将每张发票放在单独的页面中。
标签: c# jquery asp.net-mvc asp.net-mvc-3 jquery-ui