Problem creating Reportviewer in Asp.net mvc

Asked

Viewed 140 times

1

I installed the package "Install-Package Mvcreportviewer" via Package Manager Console and when trying to create Reportviewer gives an error not found the reference.

My code:

View

@using MvcReportViewer; <-- Aqui dá erro

<h2>Invoice</h2>
@using (Html.BeginForm("Index", "RelatorioInvoice", FormMethod.Post))
{ 
    <div>
        <label>
           <span>Invoice/Credit note: </span> 
            @Html.TextBox("Range1", "", new { @class = "form-control form-control-custom", style = "width:100px;" }) 

            <span> até </span>
             @Html.TextBox("Range2", "", new { @class = "form-control form-control-custom", style = "width:100px;" })

            <span>Série: </span> 
            @Html.TextBox("txtSerie", "", new { @class = "form-control form-control-custom", style = "width:50px", maxlength = "2" })

            <span>Tipo: </span> 
            @Html.TextBox("Tipo", "", new { @class = "form-control form-control-custom", style = "width:50px;", maxlength = "2" }) 

            <span>CIA: </span>             
            @Html.DropDownList("ItemsListCIA", null, "Sel...", new { @class = "form-control form-control-custom", style = "width:90px;" })

            <input class="btn btn-padrao-bv" type="submit" id="btnPesquisar" value="Pesquisar"/>
            @Html.ActionLink("Comentário", "Comentario", null , new { target = "_blank", @class="modal-link" })

        </label>
        <p>
            <label>
                @ViewBag.Message
            </label>
        </p>
    </div>

}

<script type="text/javascript">

    $(function () {
        $('body').on('click', '.modal-link', function (e) {
            e.preventDefault();
            $(this).attr('data-target', '#modal-container');
            $(this).attr('data-toggle', 'modal');
        });
        $('body').on('click', '.modal-close-btn', function () {
            $('#modal-container').modal('hide');
        });
        $('#modal-container').on('hidden.bs.modal', function () {
            $(this).removeData('bs.modal');
        });
        $('#CancelModal').on('click', function () {
            return false;
        });
    });

</script>

<div style="margin-top: 20px;">

    @Html.MvcReportViewer(
    "/TestReports/TestReport",
    new { Parameter1 = "Hello World!", Parameter2 = DateTime.Now, Parameter3 = 12345, Parameter4 = DateTime.UtcNow },
    new { Height = 900, Width = 900, style = "border: none" })

    <div id="modal-container" class="modal fade comentario-modal" 
    tabindex="-1" role="dialog">

    </div>
</div>

1 answer

2


Open the file ~/Views/Web.config (is not the root directory, it is another) and add the following entry:

<configuration>
  ...
  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization"/>
        <add namespace="System.Web.Routing" />
        <add namespace="MvcReportViewer" /> <!-- Esta aqui -->
        <add namespace="MeuProjeto" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>
  ...
</configuration>

If Visual Studio marks syntax error, close all Views and make a Rebuild in the solution.

  • worked, but when I try to create the "@Html.Mvcreportviewer" as in the example you sent me, it still doesn’t work. I gave Rebuild and it didn’t work.

  • What exactly doesn’t work? Gives syntax error? Does code fail to execute? Be more specific.

  • From the error in the View "Mvcreportviewer" Reference, so do not let create the "@Html.Mvcreportviewer" control like the example.

  • You can open another question detailing the error, with the specific message?

  • 1

    I redid everything here and it worked. Thanks

Browser other questions tagged

You are not signed in. Login or sign up in order to post.