RedirectToAction не отображает представление.
// Go populate and display PDF using XML file
DoPDF(stXML);
}
UpDateDropDown(model);
return RedirectToAction("ReportsSelection", "Reports");
Код перевода:
private void DoPDF(String stXML)
{
string filename = string.Concat(Guid.NewGuid().ToString(), ".pdf");
PdfReader reader = new PdfReader(new RandomAccessFileOrArray(Request.MapPath(_NFCPage._NFReference.FM_NOFEAR_PDF)), null);
// Create the iTextSharp document
// Set the document to write to memory
using (MemoryStream memStream = new MemoryStream())
{
PdfStamper ps = new PdfStamper(reader, memStream);
// Populate the PDF with values in the XML file
AcroFields af = ps.AcroFields;
ParserXML(stXML, af);
ps.FormFlattening = false;
ps.Writer.CloseStream = false;
ps.Close();
byte[] buf = new byte[memStream.Position];
memStream.Position = 0;
memStream.Read(buf, 0, buf.Length);
// Set the appropriate ContentType
Response.ContentType = "Application/pdf";
// Get the physical path to the file
Response.AddHeader("Content-disposition", string.Format("attachment; filename={0};", filename));
// Write the file directly to the HTTP content output stream.
Response.Buffer = true;
Response.Clear();
Response.BinaryWrite(memStream.GetBuffer()); //Comment out to work
Response.End(); //Comment out to work
}
}
Я заметил, что если я удаляю последние две строки в подпрограмме DoPDF, она отображает представление.