0

There was requirement of reports integration with an MVC application.

I am using MVC Report viewer from code plex MVC Report Viewer

Initially i was using the rdl file as Server Report, which was hosted on Reports Server. I was able to load the reports.

But the requirements were not to host it as Server Report, instead add the rdl file as a local report and load it during run-time.

I did the code changes as follows to load it as Local Report.

ReportViewer reportViewer = new ReportViewer();
reportViewer.ProcessingMode = ProcessingMode.Local;

var dataSet = this.FillDataSet(reportModel.ReportParameters);
reportViewer.LocalReport.ReportPath = string.Format(@"{0}Reports\{1}.rdlc", this.Request.MapPath(this.Request.ApplicationPath), reportModel.ReportName);
reportViewer.LocalReport.DataSources.Clear();
reportViewer.LocalReport.DataSources.Add(new ReportDataSource("DS_Report", dataSet.Tables[0]));
reportViewer.LocalReport.DataSources.Add(new ReportDataSource("DS_ChartforSalesRep", dataSet.Tables[0]));

reportViewer.ShowParameterPrompts = false;

reportViewer.DataBind();
reportViewer.LocalReport.Refresh();
reportViewer.ReportError += this.OnLoadReportError;

this.ViewBag.ReportViewer = reportViewer;

Data is loaded and populated into a dataset which is then provided to the report.

I am getting an exception at this line

reportViewer.DataBind();

Tried to find some help online, and most of them suggested to add scripts tag as below

<asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>

Few links - Link 1 - Link 2 - Link 3

The ReportViewerWebForm.aspx which gets added from the nuget package already had the script tag.

But still, it throws the exception The Report Viewer Web Control requires a System.Web.UI.ScriptManager on the web form

Edit 1: Content of ReportViewerWebForm.aspx

    <%@ Page Language="C#" AutoEventWireup="True" CodeBehind="ReportViewerWebForm.aspx.cs" Inherits="ReportViewerForMvc.ReportViewerWebForm" %>

<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body style="margin: 0px; padding: 0px;">
    <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server">
                <Scripts>
                    <asp:ScriptReference Assembly="ReportViewerForMvc" Name="ReportViewerForMvc.Scripts.PostMessage.js" />
                </Scripts>
            </asp:ScriptManager>
            <rsweb:ReportViewer ID="ReportViewer1" runat="server"></rsweb:ReportViewer>
        </div>
    </form>
</body>
</html>

Would be great if someone could help me on this.

Community
  • 1
  • 1
Ravi Sankar Rao
  • 1,050
  • 11
  • 26
  • I suggest you to show ASPX page content from `ReportViewerWebForm.aspx` (which bundled with `ReportViewerForMvc`) where `ReportViewer` control takes place. Is the `ReportViewer` instance generated dynamically by code? – Tetsuya Yamamoto Mar 10 '17 at 03:59
  • @TetsuyaYamamoto Hi, i have updated the question with the contents of ReportViewerWebForm.aspx – Ravi Sankar Rao Mar 10 '17 at 04:30
  • Seems that the ASPX page content is fine atm, hence it may turning into code-behind issues inside `ReportViewerWebForm.aspx.cs`. Have you include `IsPostBack` check on `Page_Load` method? – Tetsuya Yamamoto Mar 10 '17 at 04:39
  • @TetsuyaYamamoto Its actually an MVC Report Viewer being used in an MVC Application. Don't have code behind file as such. The C# code which i had shared is in a controller which returns the report viewer in view bag – Ravi Sankar Rao Mar 10 '17 at 19:17

1 Answers1

0

After few days of hit and trial found that the following line itself was an issue.

reportViewer.DataBind();

Removed the line and things started working fine. It seems, report viewer internally handles data binding. No need to explicitly bind it.

Ravi Sankar Rao
  • 1,050
  • 11
  • 26