Reputation: 2295
my application is MVC3 (ASPX views). I have a form, in the Edit view I have save button, that saves the form and return to the index page, and another button to print PDF from another ActionResult in the same controller as Edit; it there a way to save and print the PDF from one button? Here is my script for edit view:
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);
}
and here is the script for printing the 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;
}
}
Thanks in advance.
Upvotes: 0
Views: 1796
Reputation: 218722
If you want to get the PDF on the Save of your edit action, you may redirect to an action method which returns the PDF to browser
[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");
}
Upvotes: 2