为什么我的Crystal Report和Viewer在MVC应用程序的Web窗体上不可见?

Pro*_*ofK 4 asp.net-mvc webforms crystal-reports crystal-reports-2010

我正在将示例MVC 3应用程序中的代码复制到我的新MVC 4应用程序中.代码将报表参数设置为Session,即报表名称和报表数据,然后调用仅包含CrystalReportViewer的.aspx页面来显示报表:

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");
    }
}
Run Code Online (Sandbox Code Playgroud)

网络表格:

<%@ 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>
Run Code Online (Sandbox Code Playgroud)

这两个项目 - 我的和示例 - 几乎相同,但当我在我的项目上调用终端等报告操作时,我得到的只是一个空白页面.它上面有一个Crystal查看器,这是一个div超出我的水平的JavaScript方式.

主要工作是在后面的代码中完成的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;
}
Run Code Online (Sandbox Code Playgroud)

这在示例和我的项目中都是相同的.如果我将我的一个报告复制到示例项目中,它可以完美地工作.两个web.config文件看起来都一样.示例报告中没有"特殊"文件,而不是我的.唯一明显的区别是我的项目是一个小型解决方案中的启动项目,其中示例项目是独立的.在解决方案中,但仅在那里.

我可能有什么不对,或者可能有什么区别?我正在考虑简单地将所有报告移到示例中并从我的项目中调用它.

注意: JavaScript控制台显示以下错误:

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
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

和两个

Uncaught ReferenceError: bobj is not defined:   ReportViewer.aspx:56 ReportViewer.aspx:64
Run Code Online (Sandbox Code Playgroud)

Ror*_*ory 8

啊啊老了bobj is not defined!

这意味着您在与IIS中的默认站点不同的站点中运行ASP.安装Crystal Reports时,会放入一堆文件,C:\Inetpub\wwwroot\aspnet_client以便报表查看器工作.

解决方案:将水晶文件复制C:\Inetpub\wwwroot\aspnet_client到您的网站根文件夹下.

要获得正确的路径,请转到IIS管理器>站点> [您的网站]>右键单击>管理网站>高级设置...>物理路径.您需要的实际文件位于下方,wwwroot\aspnet_client\system_web\[framework version]\crystalreportviewers13但通常最简单的方法是将整个aspnet_client文件夹从默认的webroot 复制到您网站的webroot.