I asked a question because there is not enough information on the Internet, or the information is not complete, so you can start working.
The first thing you need to know is that the report viewer is web control, so you cannot use it in MVC, so first of all you need to create a web form so that you can add a report viewer. In the example I did, I am using Visual Studio 2010.
The web form is as follows:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Report Viewer</title>
</head>
<body>
<div style="width: auto;">
<form id="form1" runat="server" style="width: 100%; height: 100%;">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<rsweb:ReportViewer ID="rptViewer" runat="server" Width="100%" Height="100%" AsyncRendering="False"
SizeToReportContent="True">
</rsweb:ReportViewer>
</form>
</div>
</body>
</html>
Code behind the web form:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
var reportServer = ConfigurationManager.AppSettings["ReportServer"].ToString();
var reportPath = ConfigurationManager.AppSettings["ReportPath"].ToString();
rptViewer.ServerReport.ReportServerUrl = new Uri(reportServer);
rptViewer.ShowToolBar = false;
rptViewer.ServerReport.ReportPath = reportPath + Request.QueryString["ReportName"];
List<ReportParameter> parameters = new List<ReportParameter>();
string[] keys = Request.QueryString.AllKeys;
for (int i = 1; i < Request.QueryString.Count; i++)
{
parameters.Add(new ReportParameter(keys[i], Request.QueryString[i]));
}
this.ReportViewer1.ServerReport.SetParameters(parameters);
this.ReportViewer1.ProcessingMode = ProcessingMode.Remote;
this.ReportViewer1.ShowParameterPrompts = false;
this.ReportViewer1.ShowPromptAreaButton = false;
this.ReportViewer1.ServerReport.Refresh();
rptViewer.ProcessingMode = ProcessingMode.Remote;
rptViewer.ServerReport.Refresh();
}
}
MVC. : javascript iframe.
, :
<iframe id="Frame1" src="<%= Session["Url"] %>" width="230" height="230" frameborder="0"></iframe> **1
function OpenReports(name) {
var width = (screen.availWidth - 700).toString();
var height = (screen.availHeight - 100).toString();
window.open('/Reporting/Reports.aspx?ReportName=' + name,
'mywindow', 'width=' + width + ',height=' + height + ',toolbar=no,location=no,directories=yes,status=no,' +
'menubar=no,scrollbars=yes,copyhistory=yes,resizable=yes' + ',screenX=0,screenY=0,left=0,top=0');
} **2
** 1 SessionURL - , . iframe
** 2/Reporting/Reports.aspx - -, eaelier. , .
:
public ActionResult ViewName()
{
Session["Url"] = "/Reporting/Reports.aspx?ReportName=Report44";
return View();
}**1
** 1/Reporting/Reports.aspx - -, eaelier.
, Report Viewer 10, web.config:
<system.web>
<httpHandlers>
<add verb="*" path="Reserved.ReportViewerWebControl.axd" type = "Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</httpHandlers>
</system.web>
, -:)