這是早晨問(wèn)的問(wèn)題,估計(jì)沒(méi)幾率再看到了,所以貼一下
http://q.cnblogs.com/q/34069/
雖然有一個(gè)回答,但是MVC的actionz中似乎不能使用Response.Write。
看了另外的文章,有點(diǎn)感覺(jué)可能是擴(kuò)展一個(gè)ActionResult,但流的知識(shí)忘的差不多了,無(wú)法把二進(jìn)制的RDLC的數(shù)據(jù)呈現(xiàn)到頁(yè)面的一個(gè)div當(dāng)中,在頁(yè)面中我使用的是HTML.RederAction來(lái)加載報(bào)表的預(yù)覽。
這是ReportsResult
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); }
可能些的有點(diǎn)問(wèn)題。
MVC中使用RDLC報(bào)表
喵喵時(shí)光機(jī)
2018-12-07 11:44:58