0

レポートを生成する機能があります。できます。私の問題は、C# で MVC3 を使用していて、レポートビューアーをファイルに挿入できないことです。Cshtml. Ascx を使用してレポートを表示しようとしていますが、次のエラーが発生します。

ハンドラー 'System.Web.Mvc.HttpHandlerUtil ServerExecuteHttpHandlerWrapper +' の子要求の実行中にエラーが発生しました

relatorio.cshtmlファイルでo@Html.Partial(「relatorioApontamento」)を呼び出すと。

relatorio.cshtml

@{
    ViewBag.Title = "relatorio";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<script src="@Url.Content("~/Scripts/relatorio.js")" type="text/javascript"></script>
@using (Html.BeginForm("relatorio", "Paginas", FormMethod.Post, new { @id = "frmParametroConfigPath" }))
{
   <div id="relatorio">
        <h1 class="titulo">Relatório</h1>
        <div class="boxRecurso">
            <label id="lbl_recurso">Recurso:</label><br />
            <select ID="ddl_nm_recurso" class="txtRecurso"></select>
        </div>
        <div class="boxDataInicial">
            <label id="lbl_data_inicial">Data Inicial:</label><br />
            <input type="text" id="datepicker_ida" />
        </div>
        <div class="boxDataFinal">
            <label id="lbl_data_final">Data Final:</label><br />
            <input type="text" id="datepicker_volta" />
        </div>
        <div id="box_btnGerar">
            <input type="button" ID="btnGerar" class="botao" value="Gerar" />
        </div>
    </div>
    @Html.Partial("relatorioApontamento");

relatorioApontamento.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="relatorioApontamento.ascx.cs" Inherits="ControleBU.Views.Paginas.relatorioApontamento" %>
<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
     <asp:ScriptManager ID="scriptManager" runat="server"></asp:ScriptManager>
<rsweb:ReportViewer ID="rv" runat="server" Height="679px" Width="1300px">
</rsweb:ReportViewer>

relatorioApontamento.ascx.cs

namespace ControleBU.Views.Paginas
{
    public partial class relatorioApontamento : System.Web.Mvc.ViewUserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["item"] != null)
            {
                rv.LocalReport.ReportPath = "Reports\\Report1.rdlc";
                rv.LocalReport.DataSources.Add((ReportDataSource)Session["item"]);
                rv.LocalReport.SetParameters(new ReportParameter("TotalHoras", Convert.ToInt32(Math.Truncate(((TimeSpan)Session["TotalHoras"]).TotalHours)).ToString() + ":" + ((TimeSpan)Session["TotalHoras"]).Minutes.ToString()));
                rv.LocalReport.SetParameters(new ReportParameter("Ida", Convert.ToString(Session["DataInicio"])));
                rv.LocalReport.SetParameters(new ReportParameter("Volta", Convert.ToString(Session["DataFim"])));
                rv.LocalReport.Refresh();
            }

        }
    }
}

Paginas コントローラーの関数

public int gerarRelatorioRelatorio(DateTime datepicker_ida, DateTime datepicker_volta, string ddl_nm_recurso)
        {
            try
            {
                ProjectBoxDAL dalProjectBox = new ProjectBoxDAL();
                Softbox.DashBordGBU.Reports.dtsReportRecurso dt = new Softbox.DashBordGBU.Reports.dtsReportRecurso();

                BUProjetosDAL dalBuProjetos = new BUProjetosDAL();

                int codRecurso = Convert.ToInt32(ddl_nm_recurso);
                int codCliente = dalBuProjetos.retornaCodigoClienteRecurso(codRecurso);

                IDataReader dr = dalProjectBox.relatorioRecurso(codCliente, datepicker_ida, datepicker_volta, codRecurso);

                dt.Tables[0].Load(dr);

                if (dt.Tables[0].Rows.Count > 0)
                {
                    var total = dt.ReportRecurso.AsEnumerable().Sum(x => x.horas_ms);

                    TimeSpan totalHoras = TimeSpan.FromMilliseconds(total);

                    Microsoft.Reporting.WebForms.ReportDataSource item = new Microsoft.Reporting.WebForms.ReportDataSource();
                    item.Value = dt.Tables[0];
                    item.Name = "ReportRecurso";

                    ReportViewer rv = new Microsoft.Reporting.WebForms.ReportViewer();
                    Session["DataInicio"] = datepicker_ida;
                    Session["DataFim"] = datepicker_volta;
                    Session["ddl"] = ddl_nm_recurso;
                    Session["TotalHoras"] = totalHoras;
                    Session["Item"] = item;

                    return 1;
                }
                else
                    return 2;

            }
            catch (Exception)
            {
                return 0;
            }
        }
4

1 に答える 1