我几乎到处寻找解决此问题的方法,但还没有找到对我有用的方法。我在我们的托管服务器上设置了一个报告服务器 (2008 R2)。我使用报告生成器从头开始创建了一个报告,并在使用其 URL 登录到报告服务器时对其进行了测试,并成功生成了报告。

当我尝试从我们的 MVC 应用程序查看报告时,只有报告工具栏呈现(显示导出、打印、页面和查看报告按钮)。它显示它正在“加载”,完成后它只是一个空白报告,但它在工具栏上显示了正确的参数,如果我更改代码中的参数名称,它会返回一个错误,说明该参数没有“存在;所以我知道地址用户/密码信息是正确的。

页面的代码和标记

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Import Namespace="Comp.Proj.Core.Model"%>
<%@ Import Namespace="Comp.Proj.Core.Service" %>
<%@ Import Namespace="Microsoft.Reporting.WebForms" %>
<%@ Import Namespace="System.Security.Principal" %>
<%@ Import Namespace="System.Net" %>
<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

  <h2><a href="/Reporting">Back to Reports</a> / <%=ViewData["Report"]%></h2>
    <form action="/Reporting/DateViewer" method="get">
      Start Date:
      <input type="text" name="start" class="datepicker" value="<%=ViewData[" Start "] %>" /> End Date:
      <input type="text" name="end" class="datepicker" value="<%=ViewData[" End "] %>" />
      <input type="hidden" name="id" value="<%=ViewData[" Report "] %>" />
      <input type="submit" class="button" value="Run" />
    </form>

    <script runat="server" language="C#">
      protected void Page_Load(object sender, EventArgs e) {
        try {
          if (!IsPostBack) {
            if (ViewData["Start"] != null) {
              var param = new List < ReportParameter > ();


              var start = new ReportParameter("start", ViewData["Start"].ToString());
              var end = new ReportParameter("end", ViewData["End"].ToString());
              var region = new ReportParameter("region", "2");
              param.Add(start);
              param.Add(end);
              param.Add(region);
              ReportViewer1.Width = 1100;
              ReportViewer1.Height = 900;
              ReportViewer1.ShowCredentialPrompts = false;
              ReportViewer1.ShowDocumentMapButton = false;
              ReportViewer1.ShowExportControls = true;
              ReportViewer1.ShowFindControls = false;
              ReportViewer1.ShowPrintButton = true;
              ReportViewer1.ShowPromptAreaButton = false;
              ReportViewer1.ShowRefreshButton = false;
              ReportViewer1.ShowToolBar = true;
              ReportViewer1.ShowZoomControl = false;
              ReportViewer1.SizeToReportContent = true;
              ReportViewer1.ProcessingMode = ProcessingMode.Remote;
              IReportServerCredentials irsc =
                new CustomReportCredentials(ConfigurationManager.AppSettings["ReportServerUser"],
                                            ConfigurationManager.AppSettings["ReportServerPassword"], "SERVERNAME");
              ReportViewer1.ServerReport.ReportServerCredentials = irsc;
              ReportViewer1.ServerReport.ReportServerUrl =
                new Uri(string.Format("http://{0}/ReportServer",
                                      ConfigurationManager.AppSettings["ReportServerUrl"]));
              ReportViewer1.ServerReport.ReportPath = string.Format("/{0}", ViewData["Report"]);
              ReportViewer1.ServerReport.SetParameters(param);
              ReportViewer1.ShowReportBody = true;
              ReportViewer1.ServerReport.Refresh();
            }
          }
        } catch (Exception ex) {
          Response.Write(ex.Message);
        }
      }
    </script>

    <form id="form1" runat="server">
      <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
      <div>
        <rsweb:ReportViewer ID="ReportViewer1" runat="server" />
      </div>
    </form>

</asp:Content>

网络配置

<assemblies>
    <add assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
    <add assembly="Microsoft.ReportViewer.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
</assemblies>

<buildProviders>
    <add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</buildProviders>

<system.webServer>
    <handlers>
        <add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </handlers>
</system.webServer>

最佳答案

我终于让它工作了。对于那些与我有相同问题的人,这就是我为使其正常工作所做的工作。

在页面指令中,设置 EnableEventValidation="false" 并为报表控件设置 AsyncRendering="false"

关于c# - ReportViewer 控件不显示报告,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17575351/

10-15 19:00