I copy the code from the MVC 3 sample application to my new MVC 4 application. The code sets the report parameters to the session, that is, the report name and report data, and then calls the .aspx page with only CrystalReportViewer to show the report:
public class ReportController : Controller { public ActionResult Terminal() { Session["ReportName"] = "Terminal.rpt"; using (var sqn = new SqlConnection("Data Source=(Local);Initial Catalog=ParkPay;Integrated Security=SSPI;MultipleActiveResultSets=True;")) { var adap = new SqlDataAdapter("select * from parkpay.Terminal", sqn); var dt = new DataTable(); adap.Fill(dt); Session["ReportData"] = dt; } return RedirectToAction("ShowReport", "AspxReportViewer"); } } public class AspxReportViewerController : Controller { public void ShowReport() { Response.Redirect("~/AspxForms/ReportViewer.aspx"); } }
Web Form:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ReportViewer.aspx.cs" Inherits="ParkPay.Reports.Crystal.AspxForms.ReportViewer" %> <%@ Register Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" Namespace="CrystalDecisions.Web" TagPrefix="CR" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form" runat="server"> <CR:CrystalReportViewer ID="CrystalReportViewer" runat="server" AutoDataBind="true" /> </form> </body> </html>
The two projects β mine and the example β are almost identical, but when I invoke a report action such as Terminal in my project, all I get is an empty page. It has a Crystal viewer on it, which is a div full of JavaScript methods beyond my level.
The main work is done in the code for ReportViewer.aspx :
protected void Page_Load(object sender, EventArgs e) { var reportDoc = new ReportDocument(); var reportName = Session["ReportName"].ToString(); var dataSource = Session["ReportData"] as DataTable; var reportPath = Path.Combine(Server.MapPath("~/Reports"), reportName); reportDoc.Load(reportPath); reportDoc.SetDataSource(dataSource); CrystalReportViewer.ReportSource = reportDoc; }
This is identical both in the example and in my project. If I copy one of my reports into a sample project, it works just fine. Both web.config files look the same. In the sample report, there are no "special" files not in mine. The only obvious difference is my project is the launch project in a small solution, where the sample project is autonomous. In the decision, but only there.
What could be wrong with mine, or what's the difference? I'm thinking of just moving all my reports to an example and accessing it from my project.
NOTE. The JavaScript console shows these errors:
Failed to load resource: the server responded with a status of 404 (Not Found): http://localhost:17441/aspnet_client/system_web/4_0_30319/crystalreportviewers13/js/crviewer/crv.js
and
Failed to load resource: the server responded with a status of 404 (Not Found): http://localhost:17441/aspnet_client/system_web/4_0_30319/crystalreportviewers13/js/crviewer/images/style.css
and two
Uncaught ReferenceError: bobj is not defined: ReportViewer.aspx:56 ReportViewer.aspx:64