我有一个下拉菜单,用于选择我要呈现的报告之一。因此,它将是动态的。我已经看到开发人员使用iframe或称为ReportViewerforMvc的NuGet包从MVC中的Web窗体使用ReportViewer Control。但是我无法使其工作,因为我不想刷新整个页面,只想刷新将包含报告的一个div的内容。我创建了一个将由ajax调用的控制器。
到目前为止,这是我的最新动态:
public ActionResult ReportPartial(string reportName)
{
var reportViewer = new ReportViewer();
reportViewer.ProcessingMode = ProcessingMode.Remote;
reportViewer.SizeToReportContent = true;
reportViewer.ZoomMode = ZoomMode.PageWidth;
reportViewer.Width = Unit.Percentage(100);
reportViewer.Height = Unit.Percentage(100);
reportViewer.AsyncRendering = true;
var reportInfo = GetReportInfo(reportName);
reportViewer.ServerReport.ReportServerUrl = new Uri(reportInfo.Item1);
reportViewer.ServerReport.ReportPath = reportInfo.Item2;
ViewBag.ReportViewer = reportViewer;
var reportView = PartialView("ReportPartial");
return reportView;
}
部分视图仅基于Web表单控件呈现报告
@using ReportViewerForMvc;
<div id="reportDIV">
@if (ViewBag.ReportViewer != null)
{
@Html.ReportViewer(ViewBag.ReportViewer as Microsoft.Reporting.WebForms.ReportViewer, new { scrolling = "no" })
}
</div>
在客户端,Ajax调用ReportPartial Action方法,该方法应呈现以带回视图,或者就是我期望的那样。
function generateReport(reportName) {
$('#reportView').empty();
$.ajax({
url: baseUrl + 'Report/ReportPartial',
async:true,
type: "POST",
data: JSON.stringify({ reportName: reportName}),
dataType: "html",
contentType: "application/json; charset=utf-8",
success: function (result) {
$('#reportView').html(result);
$('#reportView').show();
},
error: function (jqXHR, status, errorThrown) {
kendo.alert("Cannot connect to Sever! Contact Administrator");
}
});
虽然我无法使其正常运行,但它一直在说找不到资源,我也不知道我在做什么。
这里是NuGet包添加的ReportViewerWebForm.aspx文件,它负责创建iframe
<!DOCTYPE html>
<div id="report" runat="server" 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>
</div>
</html>
运行时出现错误,提示它无法解析rsweb.reportViewer。
任何帮助将不胜感激。