我的问题涉及尝试在我的MVC应用程序中包含SSRS(SQL Server)报告。
我已经确定了将WebForm与ReportViewer Control配合使用的混合解决方案,然后在我的MVC View页面上使用iframe引用此WebForm页面。棘手的部分是iframe需要使用报表动态填充,而不是使用src,因为将参数发布到WebForm。
它在Firefox和Chrome中完美运行,但IE会抛出“Sys is Undefined”javascript错误。
在iframe中使用src在IE中工作,但我找不到发布参数的方法(由于可能的长度,不想使用/Report.aspx?param1=test之类的东西)。
如果有任何帮助,它是一个ASP.NET MVC 2项目,.NET 4,Windows 7 x74上的Visual Studio 2010。
所以这里是代码(我可以提供VS2010项目文件,如果有人想要的话)
在我的网络表单中:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Report.aspx.cs" Inherits="SSRSMVC.Views.Home.Report" %>
<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<form id="RSForm" runat="server">
<asp:ScriptManager ID="ScriptManager" runat="server" EnablePartialRendering="true" ScriptMode="Release">
</asp:ScriptManager>
<asp:UpdatePanel ID="ReportViewerUP" runat="server">
<ContentTemplate>
<rsweb:ReportViewer ID="ReportViewer" runat="server" Width="100%" Height="380px" ProcessingMode="Local"
InteractivityPostBackMode="AlwaysAsynchronous" AsyncRendering="true">
<LocalReport ReportPath="Models\\TestReport.rdlc">
</LocalReport>
</rsweb:ReportViewer>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
和Codebehind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;
namespace SSRSMVC.Views.Home
{
public partial class Report : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string test = Request.Params["val1"];
ReportViewer.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", new SSRSMVC.Models.DataProvider().GetData()));
}
}
}
}
最后是我的View页面,
<script type="text/javascript">
$(window).load(function () {
$.post('/Report.aspx', { val1: "Hello World" }, function (data) {
var rv_frame = document.getElementById('Frame1');
rv_frame = (rv_frame.contentWindow) ? rv_frame.contentWindow : (rv_frame.contentDocument.document) ? rv_frame.contentDocument.document : rv_frame.contentDocument;
rv_frame.document.open();
rv_frame.document.write(data);
rv_frame.document.close();
});
});
</script>
答案 0 :(得分:3)
解决方案似乎是使用表单元素发布然后填充iframe,我还发布了一个Microsoft Connect错误,因为iframe中的任何Microsoft AJAX导致JavaScript错误“sys is undefined”,我试过1脚本管理器和1更新面板,并得到相同的错误。
解决方法代码,
<div id="HiddenFormTarget" style="display:none;"></div>
<iframe frameborder="0" id="Frame1" name="Frame1" style="width: 100%;height: 400px; overflow: hidden;">
</iframe>
<script type="text/javascript">
function ProcessReport() {
var form = $('<form method="post" target="Frame1" action="/Report.aspx"></form>');
form.append('<input type="hidden" id="val1" name="val1" value="Hello World!!!" />');
$("#HiddenFormTarget").append(form);
form.submit();
$("#HiddenFormTarget").empty();
}
$(window).load(function () {
ProcessReport();
});
$("H2").click(function () { ProcessReport(); });
</script>