第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在MVC中將RDLC的二進(jìn)制流數(shù)據(jù)通過(guò)RenderAction顯示到頁(yè)面上面

在MVC中將RDLC的二進(jìn)制流數(shù)據(jù)通過(guò)RenderAction顯示到頁(yè)面上面

海綿寶寶撒 2018-12-07 07:47:08
public static class HotelReport { public static byte[] GenerateReport(string dtatSetName, IEnumerable dataSource, string reportFilePath,string reportType, out string mimeType, out string encoding, out string fileNameExtension) { //報(bào)表數(shù)據(jù)源 ReportDataSource reportDataSource = new ReportDataSource(dtatSetName, dataSource); //本地化報(bào)表 LocalReport localReport = new LocalReport(); localReport.ReportPath = reportFilePath; localReport.DataSources.Add(reportDataSource); string deviceInfo = "<DeviceInfo>" + " <OutputFormat>" + reportType + "</OutputFormat>" + " <PageWidth>8.5in</PageWidth>" + " <PageHeight>11in</PageHeight>" + " <MarginTop>0.5in</MarginTop>" + " <MarginLeft>1in</MarginLeft>" + " <MarginRight>1in</MarginRight>" + " <MarginBottom>0.5in</MarginBottom>" + "</DeviceInfo>"; Warning[] warnings; string[] streams; byte[] renderedBytes; renderedBytes = localReport.Render( reportType, deviceInfo, out mimeType, out encoding, out fileNameExtension, out streams, out warnings); return renderedBytes; } } 上面是用于將RDLC報(bào)表轉(zhuǎn)換為二進(jìn)制數(shù)據(jù)的方法。 下面的ReporesRelsult用于將這種數(shù)據(jù)寫(xiě)到輸出當(dāng)中 public class ReportsResult : ActionResult { public ReportsResult(byte[] data, string mineType) { this.Data = data; this.MineType = mineType; } public byte[] Data { get; set; } public string MineType { get; set; } public override void ExecuteResult(ControllerContext context) { if (Data == null) { new EmptyResult().ExecuteResult(context); return; } context.HttpContext.Response.ContentType = MineType; using (MemoryStream ms = new MemoryStream(Data)) { ms.Position = 0; using (StreamReader sr = new StreamReader(ms)) { context.HttpContext.Response.Output.Write(sr.ReadToEnd()); } } } } 下面是控制器的action方法: public ActionResult EmployeesNumberPerYear() { string dtatSetName = "DsENPerYear"; var dataSource = EmployeeReports.EmployeesNumberPerYear(employeeRepository); string reportFilePath = Server.MapPath("~/RDLC/Employee/EmployeesNumberPerYear.rdlc"); string reportType = "PDF"; string mimeType; string encoding; string fileNameExtension; byte[] renderedBytes = HotelReport.GenerateReport(dtatSetName, dataSource, reportFilePath, reportType, out mimeType, out encoding, out fileNameExtension); return new ReportsResult(renderedBytes, mimeType); } 以及html的調(diào)用: <div> @{ Html.RenderAction("EmployeesNumberPerYear", "EmployeeReports"); }</div> 其實(shí)問(wèn)題就在于擴(kuò)展的ActionResult,怎樣將報(bào)表生成的RDLC轉(zhuǎn)換過(guò)的二進(jìn)制數(shù)據(jù)通過(guò)HttpContext來(lái)進(jìn)行輸出,并且RenderAction能夠正確的顯示出預(yù)覽。 另外要說(shuō)明的是,如果直接通過(guò)連接或url訪問(wèn)該action,excel的格式會(huì)直接用于保存,pdf的會(huì)顯示出來(lái)。但我想讓數(shù)據(jù)以預(yù)覽的形式展示到div當(dāng)中。
查看完整描述

1 回答

?
Helenr

TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超4個(gè)贊

EmployeesNumberPerYear是通過(guò)Ajax調(diào)用的嗎?

查看完整回答
反對(duì) 回復(fù) 2019-01-21
  • 1 回答
  • 0 關(guān)注
  • 680 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)