RDLC报告数据错误

时间:2018-04-19 07:59:34

标签: c# asp.net-mvc rdlc

我的ASP.Net中的RDLC报告存在问题。

这是我的函数转换为pdf的代码:

    public ActionResult Reports(string ReportType, int reportId)
    {

        LocalReport localreport = new LocalReport();
        localreport.ReportPath = Server.MapPath("~/Reports/Report_Reservatie.rdlc");

        ReportDataSource reportDataSource = new ReportDataSource();
        reportDataSource.Name = "DataSet_Reservaties";
        reportDataSource.Value = storeDB.Reservaties.FirstOrDefault(a => a.ReservatieId == reportId);

        localreport.DataSources.Add(reportDataSource);

        string reportType = ReportType;
        string mimeType;
        string encoding;
        string fileNameExtension;

        if (reportType == "PDF")
        {
            fileNameExtension = "pdf";
        }
        else
        {
            fileNameExtension = "jpg";
        }
        string[] streams;
        Warning[] warnings;
        byte[] renderedByte;
        renderedByte = localreport.Render(reportType, "", out mimeType, out encoding, out fileNameExtension, out streams, out warnings);
        Response.AddHeader("content-disposition", "attachment:filename + reservaties_report." + fileNameExtension);
        return File(renderedByte, fileNameExtension);
    }
}

这是我的视图中的代码:

@model int
@{
ViewBag.Title = "Checkout Complete";
}
<h2>@MyApplication.Resources.ResourceNL.CheckoutComplete</h2>
<p>@MyApplication.Resources.ResourceNL.ThankForTheOrder: @Model</p>

@Html.ActionLink("Export to PDF", "Reports", new { ReportType = "PDF",             reportId = @Model}, null)

但我仍然得到这个错误消息:

报表数据源对象的类型必须为System.Data.DataTable,System.Collections.IEnumerable或System.Web.UI.IDataSource。

有人可以解释一下我做错了什么吗?我真的找不到问题...

0 个答案:

没有答案