這是早晨問的問題,估計沒幾率再看到了,所以貼一下
http://q.cnblogs.com/q/34069/
雖然有一個回答,但是MVC的actionz中似乎不能使用Response.Write。
看了另外的文章,有點感覺可能是擴展一個ActionResult,但流的知識忘的差不多了,無法把二進制的RDLC的數(shù)據(jù)呈現(xiàn)到頁面的一個div當中,在頁面中我使用的是HTML.RederAction來加載報表的預(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); }
可能些的有點問題。
- 1 回答
- 0 關(guān)注
- 453 瀏覽
添加回答
舉報
0/150
提交
取消