0

我的应用程序是 MVC3(ASPX 视图)。我有一个表单,在编辑视图中我有保存按钮,用于保存表单并返回到索引页面,以及另一个按钮,用于从与编辑相同的控制器中的另一个 ActionResult 打印 PDF;有没有一种方法可以通过一个按钮保存和打印 PDF?这是我的编辑视图脚本:

 public ActionResult EditCTAH(long learnerID = 0, long caseListID = 0)
    {

        ViewBag.caseListID = (long)Session["_CTA_CaseListId"];
        try
        {
            CTAHFormEdit ctform = _learnerscaseListsSvc.GetCTAHForm(learnerID, caseListID);
            return View(ctform);
        }
        catch
        {
            return null;
        }
    }

    [HttpPost]
    public ActionResult EditCATH(CTAHFormEdit ctform)
    {
        if (ModelState.IsValid)
        {
            _learnerscaseListsSvc.EditCTAHForm(ctform);
            long courseId = (long)Session["_CTA_CourseId"];
            long caseId = (long)Session["_CTA_CaseId"];
            long caselistId = (long)Session["_CTA_CaseListId"];
            return RedirectToAction("Index", new { courseId = courseId, caseId = caseId, caselistId = caselistId });
        }

        return View(ctform);
    }

这是打印 PDF 的脚本:

   public ActionResult EvaluationCATH_PDF(long learnerID = 0, long caseListID = 0)
        {
            try
            {
.....
    pdfStamper.Close();
                byte[] byteInfo = workStream.ToArray();
                SendPdfToBrowser(byteInfo, cth.Learner_ID, cth.StudyCase_ID);
                return null;
            }
            catch
            {
                return null;
            }
        }

提前致谢。

4

1 回答 1

1

如果您想在保存编辑操作时获取 PDF,您可以重定向到将 PDF 返回到浏览器的操作方法

[HttpPost]
public ActionResult EditCATH(CTAHFormEdit ctform)
{
    if (ModelState.IsValid)
    {
     //Saved succesfully, lets show the pdf in browser.
      return RedirectToAction("Print",new { id=someIdValue});
    }
    return View(ctform);
}
public ActionResult Print(string id)
{
   byte[] pdfByteArray=GetByteArrayFromPassedID(id);
   return File(pdfByteArray,"application/pdf","somefriendlyname.pdf");
}
于 2012-09-18T19:57:47.563 回答