【发布时间】:2016-02-28 08:22:08
【问题描述】:
我正在做一个 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();
}
在两种视图(桌面和移动)上,我都这样称呼它:
@Html.ActionLink("Download pdf", "getPDF", new { snr = @bok.CBSupplierId, bnr = @bok.CBBookingCode, bgn = (int)bok.Id })
所以当我在桌面视图中按下链接时,它会下载 PDF 而不会重定向我。但是当我在使用 jquery mobile 构建的移动视图中按下它时,它会将我重定向到:/Home/getPDF?snr=22558&bnr=IWVY99&bgn=4391
【问题讨论】:
-
你能发布给你带来麻烦的代码吗?
-
是的,很抱歉它丢失了。已编辑。
标签: asp.net-mvc pdf jquery-mobile abcpdf