New to RDLC integration to MVC View #Error when rendering some fields
===


I have recently created my first RDLC report using Visual Studio 2010 to my MVC application.

I used Report Wizard to create Report1.rdlc and I run the following controller code to render output to a PDF.

My data source when the report runs references Site Object in my Model. Everything runs fine but 2 of the 4 columns in the output are rendered as #Error

Both columns have data in them for every record, there are no nulls

The only thing that makes the 2 #Error columns different from the ones that render is that they are a level down the model. i.e. of the 4 columns :

1st field SiteDescription renders OK
2nd field SiteOperator renders value as #Error for each row
3rd field SiteStatus renders value as #Error for each row
4th field CapacityMW renders OK

NB: SiteOperator is Site.SiteOperator.Operator. Similar for 3rd field. The 1st and forth are fields in the Site table (i.e. top level of model in this case)

QUESTION: Is there something else developer has to do to allow RDLC to work with existing objects from the Model? i.e. I noticed the report wizard creates a Report1.rdlc.xml file, perhaps this has to be modified, I have ran out of ideas on this one. Any comments greatly appreciated

Here is my controller code :

            private void RenderReport(string ReportPath, object Model)
        {

            var localReport = new LocalReport { ReportPath = ReportPath };

            //Report 1
            //Give the collection a name (DataSet1) so that we can reference it in our report designer
            var reportDataSource = new ReportDataSource("DataSet1", Model);
            localReport.DataSources.Add(reportDataSource);

            //Report 2
            //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();
        }


