none
在MVC中将RDLC报表以预览的形式呈现的某个DIV当中 RRS feed

  • 问题

  • 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());
                    }
                }
            }
        }

    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);
            }

    <div>
        @{
            Html.RenderAction("EmployeesNumberPerYear", "EmployeeReports");
        }
    </div>

    • 已移动 Lie You 2012年4月5日 3:19 (发件人:.NET Framework 一般性问题讨论区)
    2012年4月1日 1:43

全部回复