Note that there are some explanatory texts on larger screens.

plurals
  1. POHow I use reportviewer in C# MVC3
    text
    copied!<p>I have a function that generates a report. It works. My problem is that I use MVC3 in C # and I can not insert a reportviewer in a file. Cshtml. Ascx I am using to try to show the report, but the following error occurs: </p> <p><strong>Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil ServerExecuteHttpHandlerWrapper +'</strong></p> <p>when I call o@Html.Partial ("relatorioApontamento") in relatorio.cshtml file.</p> <p><strong>relatorio.cshtml</strong></p> <pre><code>@{ ViewBag.Title = "relatorio"; Layout = "~/Views/Shared/_Layout.cshtml"; } &lt;script src="@Url.Content("~/Scripts/relatorio.js")" type="text/javascript"&gt;&lt;/script&gt; @using (Html.BeginForm("relatorio", "Paginas", FormMethod.Post, new { @id = "frmParametroConfigPath" })) { &lt;div id="relatorio"&gt; &lt;h1 class="titulo"&gt;Relatório&lt;/h1&gt; &lt;div class="boxRecurso"&gt; &lt;label id="lbl_recurso"&gt;Recurso:&lt;/label&gt;&lt;br /&gt; &lt;select ID="ddl_nm_recurso" class="txtRecurso"&gt;&lt;/select&gt; &lt;/div&gt; &lt;div class="boxDataInicial"&gt; &lt;label id="lbl_data_inicial"&gt;Data Inicial:&lt;/label&gt;&lt;br /&gt; &lt;input type="text" id="datepicker_ida" /&gt; &lt;/div&gt; &lt;div class="boxDataFinal"&gt; &lt;label id="lbl_data_final"&gt;Data Final:&lt;/label&gt;&lt;br /&gt; &lt;input type="text" id="datepicker_volta" /&gt; &lt;/div&gt; &lt;div id="box_btnGerar"&gt; &lt;input type="button" ID="btnGerar" class="botao" value="Gerar" /&gt; &lt;/div&gt; &lt;/div&gt; @Html.Partial("relatorioApontamento"); </code></pre> <p><strong>relatorioApontamento.ascx</strong></p> <pre><code>&lt;%@ Control Language="C#" AutoEventWireup="true" CodeBehind="relatorioApontamento.ascx.cs" Inherits="ControleBU.Views.Paginas.relatorioApontamento" %&gt; &lt;%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %&gt; &lt;asp:ScriptManager ID="scriptManager" runat="server"&gt;&lt;/asp:ScriptManager&gt; &lt;rsweb:ReportViewer ID="rv" runat="server" Height="679px" Width="1300px"&gt; &lt;/rsweb:ReportViewer&gt; </code></pre> <p><strong>relatorioApontamento.ascx.cs</strong></p> <pre><code>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(); } } } } </code></pre> <p><strong>function in Paginas Controller</strong></p> <pre><code>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 &gt; 0) { var total = dt.ReportRecurso.AsEnumerable().Sum(x =&gt; 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; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload