Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc ABC Pdf mobile未正确下载Pdf_Asp.net Mvc_Pdf_Jquery Mobile_Abcpdf - Fatal编程技术网

Asp.net mvc ABC Pdf mobile未正确下载Pdf

Asp.net mvc ABC Pdf mobile未正确下载Pdf,asp.net-mvc,pdf,jquery-mobile,abcpdf,Asp.net Mvc,Pdf,Jquery Mobile,Abcpdf,我正在做一个c sharp MVC项目,并将其中一个HTML页面呈现为PDF。 当我从桌面版本调用它时,PDF会自动下载,而不会重定向我。 但当我在page.mobile.cshtml上并按下下载pdf按钮时,它会将我重定向到GetPDF方法的url。如果我刷新该站点,它将下载pdf 我在这里做错了什么,是移动视图的一些路由设置错了吗 这是我的getPdf方法: public void getPdf(string snr, string bnr, int bgn) {

我正在做一个c sharp MVC项目,并将其中一个HTML页面呈现为PDF。 当我从桌面版本调用它时,PDF会自动下载,而不会重定向我。 但当我在page.mobile.cshtml上并按下下载pdf按钮时,它会将我重定向到GetPDF方法的url。如果我刷新该站点,它将下载pdf

我在这里做错了什么,是移动视图的一些路由设置错了吗

这是我的getPdf方法:

public void getPdf(string snr, string bnr, int bgn)
        {
            Doc theDoc = new Doc();
            theDoc.Clear();
            theDoc.FontSize = 16;

            theDoc.Page = theDoc.AddPage();

            int theID;

            string url = this.Url.Action("TicketPdf", "Home", new { supplierCode = snr, bookingNr = bnr, bgn = bgn }, this.Request.Url.Scheme);

            theID = theDoc.AddImageUrl(url);

            while (true)
            {
                theDoc.FrameRect();
                if (!theDoc.Chainable(theID))
                    break;
                theDoc.Page = theDoc.AddPage();
                theID = theDoc.AddImageToChain(theID);
            }

            for (int i = 1; i <= theDoc.PageCount; i++)
            {
                theDoc.PageNumber = i;
                theDoc.Flatten();
            }

            byte[] theData = theDoc.GetData();
            Response.Clear();
            Response.ContentType = "application/pdf";
            //Response.AddHeader("content-disposition", "inline; filename=ticket.PDF");
            Response.AddHeader("content-length", theData.Length.ToString());

            Response.AddHeader("content-disposition", "attachment; filename=Ticket.pdf");

            Response.BinaryWrite(theData);
            Response.End();

        }

因此,当我按下桌面视图中的链接时,它会下载PDF而不重定向我。但当我在使用jquery mobile构建的移动视图中按下它时,它会将我重定向到:/Home/getPDF?snr=22558&bnr=IWVY99&bgn=4391

通过在移动视图的链接中添加rel=“external”来解决它。

通过添加rel=“external”来解决它移动视图中的链接。

您能发布给您带来麻烦的代码吗?是的,很抱歉它丢失了。编辑。你能把给你带来麻烦的代码贴出来吗?是的,很抱歉弄丢了。编辑。
@Html.ActionLink("Download pdf", "getPDF", new { snr = @bok.CBSupplierId, bnr = @bok.CBBookingCode, bgn = (int)bok.Id })