我正在尝试调用一个操作方法,该方法将创建pdf文件并保存在文件夹中,并应下载相同的文件
尝试在操作方法中使用File方法返回。
getJsonAsync('/LMS/GetBubblePlannerPDFReport?bpid=' + enroll + '&classorgradeIs=' + classorgradeIs + '&PlannerName=' + PlannerName, {}, {
callback: function (data) { }
});
操作:
[AllowAnonymous]
public ActionResult GetBubblePlannerPDFReport(string bpid, string classorgradeIs, string PlannerName)
{
CommonModel model = new CommonModel();
var data = OASIS.Web.Models.Common.GetData_HTS("BobblePlannerCollectionService.svc/GetBubblePlannerLevelDetailsPDFReport/" + bpid + "/" + classorgradeIs + "/" + PlannerName);
model.html = JsonConvert.DeserializeObject(data);
var actionPDF = new ViewAsPdf("StudentObservationWTR", model)
{
PageSize = Rotativa.Options.Size.A4,
PageOrientation = Rotativa.Options.Orientation.Portrait,
PageMargins = { Left = 10, Right = 10, Top = 20, Bottom = 0 },
};
byte[] estimatePDFData = actionPDF.BuildPdf(this.ControllerContext);
if (!System.IO.Directory.Exists(Server.MapPath("~/Abc/")))
Directory.CreateDirectory(Server.MapPath("~/Abc/"));
else
{
//System.IO.File.Delete(Server.MapPath("~/Abc/Test") + ".pdf");
System.IO.File.WriteAllBytes(Server.MapPath("~/Abc/Test") + ".pdf", estimatePDFData);
}
var fullpath = Path.Combine(Server.MapPath("~/Abc/"), "Test.pdf");
return File(fullpath, MimeMapping.GetMimeMapping(fullpath), "TestPdffile");
}