PDF文件仅显示3个或更多检查项目

时间:2016-07-09 01:25:51

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

我有一个带有可以检查的列(UniqueId)的Kendo Grid:

columns.Bound(c => c.UniqueId.ClientTemplate("<input type='checkbox'  class='primaryBox' id='#= UniqueId #' value='#= UniqueId #'>#= UniqueId #</input>");  

已检查的项目已通过javascript函数发送到ASP.NET MVC控制器(C#):

function getChecked() {        

        var ids = new Array();

        $('.primaryBox:checked').map(function (index) {
            ids.push(this.id);
        });        

        $.ajax({
            type: "POST",
            url: "/PatientReport/ExportToPDF",
            dataType: "json",
            traditional: true,
            data: { uniqueIds: ids },
            success: function (data) {
                if (data.success) {                    
                    $('#myFrame').attr('src', '/PatientReport/DownloadFile' + '?fName=' + data.fName);                   
                } else {                   
                }

            },
            error: function (jqXHR, textStatus, errorThrown) {
                $('#checkedMsg').text('@ELRegistry.Resources.Views.Patient.PatientStrings.CheckedError').show();

            }
        });
    }

在Controller中我有一个Action ExportToPDF(使用iTextSharp),它将已检查的UniqueIds放到PDF中:

[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult ExportToPDF(List<String> uniqueIds)       {

            var document = new Document(PageSize.A4.Rotate(), 3, 3, 80, 50);            

            //step 2: we create a memory stream that listens to the document
            var output = new MemoryStream();            

            PdfWriter writer = PdfWriter.GetInstance(document, output);
            writer.CloseStream = false;

            // calling PDFFooter class to Include in document
            writer.PageEvent = new PDFFooter();

            //step 3: we open the document

            document.Open();            

            // here is the code that puts to the dataTable
            ...

            and then:   

            // Add table to the document
            document.Add(dataTable);

            //This is important don't forget to close the document
            document.Close();



            byte[] byteInfo = output.ToArray();
            output.Write(byteInfo, 0, byteInfo.Length);
            output.Position = 0;          


            var fName = string.Format("File-{0}.pdf", DateTime.Now.ToString("s"));
            Session[fName] = output;

            return Json(new { success = true, fName }, JsonRequestBehavior.AllowGet);

        }

和Action DownloadFile:

public ActionResult DownloadFile(string fName)
        {
            var ms = Session[fName] as MemoryStream;
            if (ms == null)
                return new EmptyResult();
            Session[fName] = null;
            return File(ms, "application/pdf", fName);
        }

我的问题在于当我检查1或2个UniqueIds时,PDF文件没有显示它们(在JavaScript函数中我看到id,在ExportToPDF Action中一切正常,但PDF文件没有显示它们)。如果我检查3个或更多UniqueIds,PDF文件中的一切都很好。有任何想法吗?怎么解决这个?提前感谢您的帮助。

0 个答案:

没有答案