1
PDFHelper.csPDF沒有下載在Chrome本地主機和Safari
byte[] bytes = memoryStream.ToArray();
memoryStream.Close();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("content-length", bytes.Length.ToString());
HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=Report.pdf");
//HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.BinaryWrite(bytes);
HttpContext.Current.Response.End();
LoginFactory.js
factory.getPDFReport = function (data) {
var headers = { 'Content-Type': 'application/pdf;' };
var url = hostUrl + '/ReportsController/PDFReports';
return $http.post(url, data, headers).then(
function (results) {
return results;`**enter code here**`
});
}
這是我的代碼,但它是不工作的本地主機的Chrome和Safari瀏覽器。
感謝它正在工作......但它直接下載我希望它在新標籤中打開... – bhushan
你在哪裏寫下了這部分代碼? (例如:按鈕onclick事件) –
通常在您的asp.net對象上添加'target =「_ blank」'會在新窗口中觸發事件。 –