简体   繁体   English

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

[英]Why is my Crystal Report and Viewer invisible on a Web Form in an MVC application?

I'm copying code from an example MVC 3 application into my new MVC 4 application. 我正在将示例MVC 3应用程序中的代码复制到我的新MVC 4应用程序中。 The code sets report parameters into Session, ie the report name and the report data, and then calls an .aspx page with only a CrystalReportViewer on it to show the report: 代码将报表参数设置为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");
    }
}

The 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 nearly identical, yet when I call a report action such as Terminal on my project, all I get is a blank page. 这两个项目 - 我的和示例 - 几乎相同,但当我在我的项目上调用终端等报告操作时,我得到的只是一个空白页面。 It has a Crystal viewer on it, which is a div full of JavaScript way beyond my level. 它上有一个水晶观众,这是一个div充满超出了我的水平JavaScript的方式。

The main work is done in the code behind for ReportViewer.aspx : 主要工作是在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 in both the example and my project. 这在示例和我的项目中都是相同的。 If I copy one of my reports to the example project, it works perfectly. 如果我将我的一个报告复制到示例项目中,它可以完美地工作。 Both web.config files look identical. 两个web.config文件看起来都一样。 There are no 'special' files in the example report not in mine. 示例报告中没有“特殊”文件,而不是我的。 The only obvious difference is my project is the startup project in a small solution, where the example project is standalone. 唯一明显的区别是我的项目是一个小型解决方案中的启动项目,其中示例项目是独立的。 In a solution, but alone there. 在解决方案中,但仅在那里。

What could either be wrong with mine, or what could be the difference? 我可能有什么不对,或者可能有什么区别? I'm thinking of simply moving all my reports to the example and calling out to it from my project. 我正在考虑简单地将所有报告移到示例中并从我的项目中调用它。

NOTE: The JavaScript console shows these errors: 注意: 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

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 the two 和两个

Uncaught ReferenceError: bobj is not defined:   ReportViewer.aspx:56 ReportViewer.aspx:64

Aha the old bobj is not defined ! 啊,老bobj is not defined

This means you're running the ASP in a different site from the Default Site in IIS. 这意味着您在与IIS中的默认站点不同的站点中运行ASP。 When you install Crystal Reports it puts a bunch of files in C:\\Inetpub\\wwwroot\\aspnet_client that are necessary for report viewer to work. 安装Crystal Reports时,它会将一堆文件放在C:\\Inetpub\\wwwroot\\aspnet_client ,这些文件是报表查看器工作所必需的。

Solution: Copy the crystal files beneath C:\\Inetpub\\wwwroot\\aspnet_client to your website root folder. 解决方案:将C:\\Inetpub\\wwwroot\\aspnet_client下的水晶文件复制到您的网站根文件夹。

To get the right path, go to IIS Manager > Sites > [your website] > right-click > Manage Web Site > Advanced Settings... > Physical Path. 要获得正确的路径,请转到IIS管理器>站点> [您的网站]>右键单击>管理网站>高级设置...>物理路径。 The actual files you need are beneath wwwroot\\aspnet_client\\system_web\\[framework version]\\crystalreportviewers13 but it's usually simplest to just copy the entire aspnet_client folder from the default webroot to your site's webroot. 您需要的实际文件位于wwwroot\\aspnet_client\\system_web\\[framework version]\\crystalreportviewers13但通常最简单的方法是将整个aspnet_client文件夹从默认的webroot复制到您网站的webroot。

If you browse to the wwwroot folder, and drag the aspnet_client folder to your project, then it will add all the files. 如果浏览到wwwroot文件夹,并将aspnet_client文件夹拖到项目中,则会添加所有文件。

C:\\inetpub\\wwwroot C:\\的Inetpub \\ wwwroot文件

I'm still working on getting this one working, as just doing this hasn't yet been sufficient. 我仍然在努力让这个工作,因为这样做还不够。

The seemingly best article on the topic I've found so far is: http://scn.sap.com/community/crystal-reports-for-visual-studio/blog/2011/01/12/how-do-i-resolve-bobj-is-undefined-issue 到目前为止我发现的关于这个主题的看似最好的文章是: http//scn.sap.com/community/crystal-reports-for-visual-studio/blog/2011/01/12/how-do-i -Resolve-BOBJ-IS-未定义-问题

However, I've now tried steps 1 & 4, but so far have had no success... 但是,我现在尝试了第1步和第4步,但到目前为止还没有成功......

Following are the solutions to the above scenarios: 以下是上述方案的解决方案:

1.Copy the folder "crystalreportviewers12" from “C:\\Inetpub\\wwwroot\\system_web\\2_0_50727" under “Default Website” to the “Custom Website” directory in IIS. Or, create a virtual directory pointing 'aspnet_client' folder in the custom web site directory. 1.将文件夹“crystalreportviewers12”从“默认网站”下的“C:\\ Inetpub \\ wwwroot \\ system_web \\ 2_0_50727”复制到IIS中的“自定义网站”目录。或者,在自定义中创建一个指向“aspnet_client”文件夹的虚拟目录网站目录。

2.In the IIS Manger, select the Application Pool and Basic Settings. 2.在IIS Manger中,选择“应用程序池”和“基本设置”。 Under Managed Pipeline Mode, change Integrated Mode to Classic Mode. 在Managed Pipeline Mode下,将Integrated Mode更改为Classic Mode。

3.The value of resoureURI should be "~/crystalreportviewers12" not "/crystalreportviewers12". 3. resoureURI的值应该是“〜/ crystalreportviewers12”而不是“/ crystalreportviewers12”。

4.Copy the CrystalReportViewers12 folder from "C:Program Files\\Business Objects\\Common\\4.0" and paste it to "C:\\Windows\\Microsoft.NET\\Framework\\v3.5\\ASP.NETClientFiles". 4.从“C:Program Files \\ Business Objects \\ Common \\ 4.0”复制CrystalReportViewers12文件夹并将其粘贴到“C:\\ Windows \\ Microsoft.NET \\ Framework \\ v3.5 \\ ASP.NETClientFiles”。

Note: Framework may vary as per the Visual Studio version used. 注意:框架可能因使用的Visual Studio版本而异。

My Error: 我的错误:

0x800a1391 - JavaScript runtime error: 'bobj' is undefined 0x800a1391 - JavaScript运行时错误:'bobj'未定义

 bobj.crv.stateManager.setComponentState('CrystalReportViewer1__UI',eval('('+document.getElementById('__CRYSTALSTATECrystalReportViewer1').value+')')); 

Somehow I seem to have a conflict with different versions. 不知怎的,我似乎与不同的版本有冲突。 VS wants to use 4_6_30, but I seem to have elsewhere the folders for 4_0_30319... VS想要使用4_6_30,但我似乎在其他地方有4_0_30319的文件夹......

So playing around I can get it to drop the bobj error, but it still does not display the report viewer. 因此,我可以让它放弃bobj错误,但它仍然不显示报告查看器。 If specifying a report, now I just get that loading the report failed... and yet I let it create a new report via VS... 如果指定一个报告,现在我只是加载报告失败...但我让它通过VS创建一个新的报告...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM