We are using the MVC framework (release 5) and the CrystalReportViewer control to show our reports. I cannot get any of the buttons at the top of the report viewer control to work.
If I’m working with the report ‘HoursSummary’. If I hover over any of the buttons on the report viewer in IE the displayed link at the bottom of the pages is ‘../HoursSummary’. This creates a url of ‘http://localhost/HoursSummary‘. There is no ‘HoursSummary’ controller so I keep receiving 404 errors.
- I believe I want to redirect to ‘http://localhost/reports/HoursSummary‘ since I do have a reports controller. If this is the correct method does anyone know which property I should set on the CrystalReportViewer control to make that happen?
- Is there an easier method to handle this situation?
We were able to get the report viewer to work and have been using it for the past few months in production without any issues.
Everything seems to work great.
UPDATE
I’ve added some code and clarification to the steps I originally listed above. The key item I left out was there is some code behind with the final View so it will work with Crystal Reports. The code behind is minimal, but needed. For Crystal Reports to work you are going to end up with the following files:
Details on how to create a View that will work with Crystal Reports:
Once the layout Crystal Report file is completed, the AllJobsSummaryReportLayout.rpt, we design our Controller. In the Controller we take in any parameters needed to run the report, call the Model, Model returns our list of DTOs, as seen in the snippet below from the Controller:
Note a couple of items here, we are creating a varible ‘report’ that is a type of the Crystal Report layout file, AllJobsSummaryReportLayout.rpt, that we created above.
Once we created the ‘report’ variable we set the data source values and any parameters we need, and bundle the item up into the ViewData.
Now let’s take a look at AllJobsSummaryView.aspx. This file has a form on it with a Crystal Reports Viewer and a code behind file:
And the code behind file:
The Page_Unload is key, without it you will have an error generated by Crystal Reports ‘You have exceeded the max number of reports set by your administrator.’
This method is still working in a production environment for well over two years now.