我正在将代码从示例 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");
}
}
网络表单:
<%@ 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>
这两个项目(我的项目和示例)几乎相同,但是当我在项目上调用报告操作(例如“终端”)时,我得到的只是一个空白页面。它上面有一个 Crystal 查看器,这是一个充满 JavaScript 的 div
,远远超出了我的水平。
主要工作是在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;
}
这在示例和我的项目中都是相同的。如果我将一份报告复制到示例项目中,它就会完美运行。两个 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
和
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
还有两个
Uncaught ReferenceError: bobj is not defined: ReportViewer.aspx:56 ReportViewer.aspx:64
最佳答案
啊哈,旧的bobj未定义
!
这意味着您正在与 IIS 中的默认站点不同的站点中运行 ASP。当您安装 Crystal Reports 时,它会将一堆文件放入 C:\Inetpub\wwwroot\aspnet_client
中,这些文件是报表查看器正常工作所必需的。
解决方案:将C:\Inetpub\wwwroot\aspnet_client
下的crystal文件复制到您的网站根文件夹中。
要获取正确的路径,请转至 IIS 管理器 > 站点 > [您的网站] > 右键单击 > 管理网站 > 高级设置... > 物理路径。您需要的实际文件位于 wwwroot\aspnet_client\system_web\[framework version]\crystalreportviewers13
下,但通常最简单的方法是将整个 aspnet_client
文件夹从默认 Webroot 复制到您的网站的网络根目录。
关于asp.net-mvc - 为什么我的 Crystal Report 和 Viewer 在 MVC 应用程序的 Web 表单上不可见?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18037727/