ASP.Net MVC Rotative ActionAsPdf不会重定向到我的内部操作

时间:2018-05-07 09:56:05

标签: c# asp.net-mvc pdf rotativa

我正在使用旋转将特定视图导出为PDF页面而我正在使用此代码,但当它进入“ ExportPDF ”时永远不会进入 ConfirmPDFReport ,我在另一个项目中使用了相同的代码,效果很好。

public ActionResult ExportPDF(string orderId)
        {
            try
            {


                return new ActionAsPdf("ConfirmPDFReport", new {orderId = orderId })
                {
                    FileName = DateTime.Now.ToString() + "FlightTicketInfo.pdf"
                ,
                    PageOrientation = Orientation.Landscape
                ,
                    MinimumFontSize = 18
                };
            }
            catch (Exception e)
            {
                return RedirectToAction("GeneralError", "Error", new { ErrorMessage = e.Message });
            }

        }


public ActionResult ConfirmPDFReport(string orderId)
    {

        try
        {

            return View("ConfirmationPDF", FlightSearchSession);
        }
        catch (Exception e)
        {
            return RedirectToAction("GeneralError", "Error", new { ErrorMessage = e.Message, parameter = "OrderId=" + orderId });
        }
    }

1 个答案:

答案 0 :(得分:0)

  

尝试这样,它会起作用

public ActionResult ExportPDF(string orderId)
    {
        try
        {
            return View("ConfirmPDFReport", new {orderId = orderId });

        }
        catch (Exception e)
        {
            return RedirectToAction("GeneralError", "Error", new { ErrorMessage = e.Message });
        }

    }

 public ActionResult ConfirmPDFReport(string orderId)
{

    try
    {

        return new ActionAsPdf("ConfirmationPDF", FlightSearchSession) 
       {
                FileName = DateTime.Now.ToString() + "FlightTicketInfo.pdf"
            ,
                PageOrientation = Orientation.Landscape
            ,
                MinimumFontSize = 18
            };
    }
    catch (Exception e)
    {
        return RedirectToAction("GeneralError", "Error", new { ErrorMessage = e.Message, parameter = "OrderId=" + orderId });
    }
}