【问题标题】:Why is my rdlc report displaying a blankreport?为什么我的 rdlc 报告显示空白报告?
【发布时间】:2017-04-25 23:35:12
【问题描述】:

我正在尝试在我的 MVC 项目中显示 rdlc 报告。我创建了 2 个附加文件夹: - 一个用于我的数据集 - 一个包含我的rdlc 报告文件和我的网络表单aspx 文件。下面是我的网络表单Page_Load 事件的代码

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                List<Models.goodcustomers> goodcustomers= null;
                using (var dc = new MaDbContext())
                {
                    goodcustomers= dc.goodcustomers.ToList();
                    ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/RPTReports/goodcustomers.rdlc");
                    ReportViewer1.LocalReport.DataSources.Clear();
                    ReportDataSource rdc = new ReportDataSource("MyDataset", goodcustomers);
                    ReportViewer1.LocalReport.DataSources.Add(rdc);
                    ReportViewer1.LocalReport.Refresh();
                }
            }
        }

网络表单代码

<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <rsweb:ReportViewer ID="ReportViewer1" runat="server" AsyncRendering="false" SizeToReportContent="true">

        </rsweb:ReportViewer>
    </div>
    </form>
</body>

这不起作用.... 发生的情况是,当页面打开时,它会打印List&lt;Models.goodcustomers&gt; 中所有项目的单元格,但这些单元格是空白的。 显然,当我在调试时,我看到所有内容都是从数据库中检索出来的。所以我想这不是数据库连接问题

goodcustomers 是我数据库中的一个视图,我在 MVC 应用程序中创建了一个模型,我首先使用 DbContext 代码来查询数据库

知道发生了什么吗?

ps:要在我的 MVC 应用程序中显示 Web 表单,我只需使用带有 href 的 &lt;a&gt; 标签指向 aspx 文件的位置

【问题讨论】:

  • 听起来好像没有数据库问题,这可能是渲染问题。通过在浏览器检查器中查看 HTML 来检查页面源中是否确实存在这些数据,如有必要,发布输出的 HTML 内容。
  • @TetsuyaYamamoto 在答案中检查我的解决方案

标签: asp.net asp.net-mvc webforms


【解决方案1】:

我在网站上找到了解决方案。这里应该做三件事:

  • 1:将goodcustomers 转换为DataTable。然后将DataTable 作为参数传递给ReportDataSource rdc = new ReportDataSource("MyDataset", goodcustomers_converted_to_DataTable);

  • 2 : BIND 数据。在rdc 的正下方添加ReportViewer1.DataBind(); 实例化

  • 3:步骤 2 应该可以解决问题。现在你想在 MVC cshtml 视图中替换 webform,使用 &lt;iFrame&gt; 和 src 指向 aspx webform。

按照这 3 个步骤解决了我的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-17
    • 2018-02-19
    • 1970-01-01
    • 2016-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-11
    相关资源
    最近更新 更多