首页 新闻 赞助 找找看

MVC中使用RDLC报表

0
悬赏园豆:5 [已解决问题] 解决于 2012-04-01 17:45

这是早晨问的问题,估计没几率再看到了,所以贴一下

http://q.cnblogs.com/q/34069/

虽然有一个回答,但是MVC的actionz中似乎不能使用Response.Write。

看了另外的文章,有点感觉可能是扩展一个ActionResult,但流的知识忘的差不多了,无法把二进制的RDLC的数据呈现到页面的一个div当中,在页面中我使用的是HTML.RederAction来加载报表的预览。

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

可能些的有点问题。

凡一二三的主页 凡一二三 | 初学一级 | 园豆:85
提问于:2012-03-31 18:00
< >
分享
最佳答案
0

关注一下。

收获园豆:5
水晶途途 | 小虾三级 |园豆:1443 | 2012-03-31 22:51
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册