Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 为什么我的rdlc报告显示空白报告?_Asp.net_Asp.net Mvc_Webforms - Fatal编程技术网

Asp.net 为什么我的rdlc报告显示空白报告?

Asp.net 为什么我的rdlc报告显示空白报告?,asp.net,asp.net-mvc,webforms,Asp.net,Asp.net Mvc,Webforms,我正试图在我的MVC项目中显示rdlc报告。我创建了两个附加文件夹: -一个用于我的数据集 -一个包含我的rdlc报告文件和我的webformaspx文件。下面是我在Web表单的页面加载事件中的代码 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { List<Models.goodcustomers

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

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();
                }
            }
        }
受保护的无效页面加载(对象发送方,事件参数e)
{
如果(!IsPostBack)
{
List goodcustomers=null;
使用(var dc=new MaDbContext())
{
goodcustomers=dc.goodcustomers.ToList();
ReportViewer1.LocalReport.ReportPath=Server.MapPath(“~/rptrepts/goodcustomers.rdlc”);
ReportViewer1.LocalReport.DataSources.Clear();
ReportDataSource rdc=新的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>

这不起作用。。。。当页面打开时,它会打印
列表中所有项目的单元格,但这些单元格是空白的。
显然,当我调试时,我看到所有东西都是从数据库中检索到的。所以我想这不是一个数据库连接问题

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

知道发生了什么吗


ps:要在我的MVC应用程序中显示Webform,我只需使用一个带有href的
标记,指向
aspx
文件的位置,我在网站上找到了一个解决方案。这里应该做三件事:

  • 1:将
    goodcustomers
    转换为
    DataTable
    。然后将该
    DataTable
    作为参数传递到
    ReportDataSource rdc=newreportdatasource(“MyDataset”,goodcustomers\u转换为\u DataTable)

  • 2:绑定数据。添加
    ReportViewer1.DataBind()右下方
    rdc
    实例化

  • 3:步骤2应纠正该问题。现在,如果要在MVC cshtml视图中替换webform,请使用带有指向aspx webform的src的


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

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