Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.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 mvc RDLC与MVC视图集成的新功能#渲染某些字段时出错_Asp.net Mvc_Asp.net Mvc 3_Rdlc - Fatal编程技术网

Asp.net mvc RDLC与MVC视图集成的新功能#渲染某些字段时出错

Asp.net mvc RDLC与MVC视图集成的新功能#渲染某些字段时出错,asp.net-mvc,asp.net-mvc-3,rdlc,Asp.net Mvc,Asp.net Mvc 3,Rdlc,我最近使用VisualStudio2010为我的MVC应用程序创建了我的第一个RDLC报告 我使用报表向导创建Report1.rdlc,并运行以下控制器代码将输出呈现为PDF 报表运行时,我的数据源引用模型中的站点对象。一切运行正常,但输出中的4列中有2列显示为#Error 两列中的每个记录都有数据,不存在空值 唯一使2#Error列与渲染列不同的是,它们在模型中处于较低的级别。i、 e.在4栏中: 第一个字段SiteDescription呈现OK 第二个字段SiteOperator将每行的值呈

我最近使用VisualStudio2010为我的MVC应用程序创建了我的第一个RDLC报告

我使用报表向导创建Report1.rdlc,并运行以下控制器代码将输出呈现为PDF

报表运行时,我的数据源引用模型中的站点对象。一切运行正常,但输出中的4列中有2列显示为#Error

两列中的每个记录都有数据,不存在空值

唯一使2#Error列与渲染列不同的是,它们在模型中处于较低的级别。i、 e.在4栏中:

第一个字段SiteDescription呈现OK 第二个字段SiteOperator将每行的值呈现为#错误 第三个字段SiteStatus将每行的值呈现为#错误 第四场电容MmW正常

注意:SiteOperator是Site.SiteOperator.Operator。第三个字段类似。第一个和第四个是站点表中的字段(即本例中的顶级模型)

问题:开发人员还需要做些什么来允许RDLC使用模型中的现有对象吗?i、 e.我注意到报告向导创建了一个Report1.rdlc.xml文件,也许这需要修改,我已经没有这个想法了。非常感谢您的任何意见

这是我的控制器代码:

        private void RenderReport(string ReportPath, object Model)
    {

        var localReport = new LocalReport { ReportPath = ReportPath };

        var reportDataSource = new ReportDataSource("DataSet1", Model);
        localReport.DataSources.Add(reportDataSource);

        var reportType = "PDF";
        string mimeType;
        string encoding;
        string fileNameExtension;

        //The DeviceInfo settings should be changed based on the reportType
        //http://msdn2.microsoft.com/en-us/library/ms155397.aspx
        string deviceInfo =
        "<DeviceInfo>" +
        "  <OutputFormat>PDF</OutputFormat>" +
        "  <PageWidth>8.5in</PageWidth>" +
        "  <PageHeight>11in</PageHeight>" +
        "  <MarginTop>0.5in</MarginTop>" +
        "  <MarginLeft>1in</MarginLeft>" +
        "  <MarginRight>1in</MarginRight>" +
        "  <MarginBottom>0.5in</MarginBottom>" +
        "</DeviceInfo>";

        Warning[] warnings;
        string[] streams;
        byte[] renderedBytes;

        //Render the report
        renderedBytes = localReport.Render(
            reportType,
            deviceInfo,
            out mimeType,
            out encoding,
            out fileNameExtension,
            out streams,
            out warnings);

        //Clear the response stream and write the bytes to the outputstream
        //Set content-disposition to "attachment" so that user is prompted to take an action
        //on the file (open or save)
        Response.Clear();
        Response.ContentType = mimeType;
        Response.AddHeader("content-disposition", "attachment; filename=foo." + fileNameExtension);
        Response.BinaryWrite(renderedBytes);
        Response.End();
    }
private void RenderReport(字符串报告路径,对象模型)
{
var localReport=newlocalreport{ReportPath=ReportPath};
var reportDataSource=新的reportDataSource(“数据集1”,模型);
localReport.DataSources.Add(reportDataSource);
var reportType=“PDF”;
字符串模拟类型;
字符串编码;
字符串文件名扩展名;
//应根据报告类型更改DeviceInfo设置
//http://msdn2.microsoft.com/en-us/library/ms155397.aspx
字符串设备信息=
"" +
“PDF”+
“8.5英寸”+
“11英寸”+
“0.5英寸”+
“1英寸”+
“1英寸”+
“0.5英寸”+
"";
警告[]警告;
字符串[]流;
字节[]渲染字节;
//提交报告
renderedBytes=localReport.Render(
报告类型,
deviceInfo,
输出mimeType,
输出编码,
输出文件名扩展名,
流出的溪流,
发出警告);
//清除响应流并将字节写入outputstream
//将内容处置设置为“附件”,以便提示用户采取操作
//在文件上(打开或保存)
Response.Clear();
Response.ContentType=mimeType;
AddHeader(“内容处置”、“附件;文件名=foo.”+文件名扩展名);
BinaryWrite(renderBytes);
Response.End();
}

在RDLC中接收“#错误”响应时,首先要看的是Visual Studio中的“输出/调试”选项卡。对于报告引擎在呈现报告时收到的每个错误,应该有一条特定的错误消息。虽然并非总是世界上最直观的消息,但它们至少应该为您指明正确的方向。

我在MVC中使用RDLC,模型源自实体框架生成的C类(使用POCO对象模板)

现在,我的类是一个相对“扁平”的类,只有属性(空值、数字、字符串、日期时间等),没有其他对象的集合,因此可能会有所不同

我在没有使用向导的情况下创建了RDLC,但发现要在MVC中使用设计器,我必须向项目中添加一个.aspx,设计器才能工作。我还只是在模拟类中使用了公共静态方法,这些方法返回我用于报表数据源向导等使用的类型的IEnumerable

我还使用EF填充数据,因此它绝对不需要存储过程:

var data = dal.PrintFriendlies.Where( p => p.ApplicationId == applicationId );
viewer.LocalReport.DataSources.Add( new ReportDataSource( "DataSourceName" , data ) );
我还返回PDF字节,这样您的代码看起来与我使用的非常接近(我使用数据源和参数,以及子报表)


您没有描述您的类结构是什么样的,但我认为它在层次结构方面存在问题,因此您可能需要将其扁平化为报表编写者喜欢的内容。

我已设法使报表正常工作。我切换到使用存储过程并从控制器调用它。我将RDLC文件放在视图中,并将其直接渲染为PDF。我对此非常满意,因为我从未在MVC应用程序中接触过路由,也从未添加过任何带有控件或类似内容的ASP.NET页面。这是一个非常整洁干净的解决方案。

我想,当向导构建数据集时,它会使用对象iEnumerable,只创建一个二维数组。这就解释了为什么只显示顶级字段。在这种情况下,我想我应该使用它的存储过程。当然,这一定是我们将来将获得的功能,从控制器中引用已经存在的模型,并指定一个对象,而不是2d结果集。太习惯MVC,忘记RDLC是远远落后的。你们同意吗?