I have a MVC4 application in Visual Studio 2010 which contains plenty of classes. I'm trying to use them to pass in as the DataSource for a Report Definition Language Client (RDLC) file. But I can't access the classes from my assembly anywhere in the data source designer
According to the MSDN Walkthrough on Using a Business Object Data Source with the ReportViewer Web Server Control in Local Processing Mode, I should be able to do so in the Dataset Properties page
In the Dataset Properties page, in the Data source box, select global.
According to this Stackoverflow question on How to use an Object data source in report (.rdlc), when in Dataset Properties page, I should be able to create a new data source like this:
Creating a New Data source:
- Select Object and click Next.
- Browse the solution tree and select the class(es) you want to bind to.
- Click Finish.
But neither of these present as options...
When I create a new dataset, nothing shows up under Data Source:
When I click New to create a New DataSource, I just get a connection Wizard that forces me to connect to a database:
Where can I add classes from my assembly?
As a trivial example, here's an example of an object I have built into the assembly that I would expect to show up:
Public Class Employee
Public Property Name As String
Public Property ID As Integer
End Class
I would eventually like to populate this information programmatically like this:
Dim lr As New LocalReport
lr.ReportPath = Server.MapPath("~\Reports\Report1.rdlc")
lr.DataSources.Add(New ReportDataSource("Data", New Employee("Kyle",27)))
Here are a couple solutions, but I prefer the second one.
As this appears to be a bug with the MVC Web Application project type itself, you can add the report to a different project type (like Class Library). As described in the post Visual Studio 2010 Report Viewer - Object Datasource, just create a separate library for the project and add the rdlc file there. The data source configuration wizard should now look like this:
As figured out in Can't see or add Website Data Sources in RDLC report in ASP.NET MVC, you can just add an aspx page anywhere to the MVC project to trick Visual Studio into pulling in the right design time libraries.
Just do the following:
Open up the RDLC file and choose a DataSource from the dropdown: