自动打开Rotativa打印对话框

时间:2017-12-31 19:23:07

标签: asp.net-mvc asp.net-mvc-5 rotativa

我正在使用Rotativa生成视图的PDF,以打印它。

我有以下代码

public ActionResult PrintTicket(string tempTickID)
{
   //var tick = ctx.vw_printTicket.Where(e => e.noTicket == tempTickID).FirstOrDefault();
   // return View(tick);

    var report = new ActionAsPdf("PrepareTicket", new { tempTickID = tempTickID });
    return report;
}

ActionAsPdf允许我打开" PrepareTicket"以PDF格式查看然后我可以打印。

问题

问题在于我,pdf接管了我的整个页面,虽然我可以打印,但我无法访问我的程序菜单,因为它现在是PDF视图。

问题

我是否可以自动调用打印对话框而不是显示pdf?

我认为这对我的情况有用。

此致

1 个答案:

答案 0 :(得分:0)

您好我已经尝试创建一个可以解决您问题的示例。

  
      
  1. 模型
  2.   
public class Ticketinfo
{
    public string name { get; set; }
    public int quantity { get; set; }
}
  
      
  1. 创建了一个具有3种操作方法的控制器
  2.   
public class GenerateController : Controller
{

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult PrintTicket(string tempTickID)
        {
            return new ActionAsPdf("RotativaPartialViewAsPdf", new { tempTickID = tempTickID });
        }

        public ActionResult RotativaPartialViewAsPdf(string tempTickID)
        {
            Ticketinfo Ticketinfo = new Ticketinfo()
            {
                name =  "Demo",
                quantity = 5
            };

            return PartialView("_RotativaPartialViewAsPdfl", Ticketinfo);
        }

}
  
      
  1. 部分视图
  2.   
@model WebApplication6.Models.Ticketinfo
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    <link href="~/Content/bootstrap.css" rel="stylesheet" />
</head>
<body>
    <div class="container">
        <table class="table">
            <tr class="info">
                <td>Lot</td>
                <td>Name</td>
                <td>Quantity</td>
            </tr>
            <tr class="success">
                <td>@Model.name</td>
                <td>@Model.quantity</td>
            </tr>
        </table>
    </div>
</body>
</html>
  
      
  1. 索引视图
  2.   

&#13;
&#13;
 @{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
    <div>
        <iframe src="@Url.Action("PrintTicket", "Generate", new {tempTickID = "1"})" 
                width="800px" height="600px">
        </iframe>
    </div>
</body>
</html>
&#13;
&#13;
&#13;

  

输出

Output

相关问题