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