【问题标题】:SSRS Reportviewer in MVC, removing iframe scrollbars by auto-sizing iframe to fit reportMVC 中的 SSRS Reportviewer,通过自动调整 iframe 大小以适应报告来删除 iframe 滚动条
【发布时间】:2014-07-30 07:53:28
【问题描述】:

在 iframe 中呈现报表查看器时,我整理了有关消除 iframe 滚动条以支持浏览器滚动条的信息。 MVC 不支持在视图中呈现报表查看器,因此需要 iframe。

编辑:我很难找到这个解决方案(如下),因此我想我会分享。


在aspx页面中(将在iframe中呈现的页面)

$(function () {//jQuery document.ready
    // attach an event handler, whenever a 'property' of the reportviewer changes, the function will be called to adjust the height of the iframe
    Sys.Application.add_load(function () {
        $find("ReportViewer").add_propertyChanged(viewerPropertyChanged); // $.find("ReportViewer") will return the reportviewer with id "ReportViewer"
    });

    function adjustIframeSize() {
        // you can play around with these figures until your report is perfect
        var extraHeightToAvoidCuttingOffPartOfReport = 100;
        var extraWidthToAvoidCuttingOffPartOfReport = 10;

        // '#ReportViewer_fixedTable' is a portion of the report viewer that contains the actual report, minus the parameters etc
        var reportPage =  $('#ReportViewer_fixedTable');

        // get the height of the report. '#ParametersRowReportViewer' is that top part that contains parameters etc
        var newHeight = reportPage.height() + $('#ParametersRowReportViewer').height() + extraHeightToAvoidCuttingOffPartOfReport;

        // same for width
        var newWidth = reportPage.width() + extraWidthToAvoidCuttingOffPartOfReport;

        // get iframe from parent document, the rest of this function only works if both the iframe and the parent page are on the same domain    
        var reportIframe = $('#ReportViewerFrame', parent.document);

        // just make sure that nothing went wrong with the calculations, other wise the entire report could be given a very small value for height and width, thereby hiding the report
        if(newHeight>extraHeightToAvoidCuttingOffPartOfReport)
            reportIframe.height(newHeight);
        if (newWidth > extraWidthToAvoidCuttingOffPartOfReport)
            reportIframe.width(newWidth);
    }

    function viewerPropertyChanged(sender, e) {
        // only change the iframe dimensions when 'isLoading'
        if (e.get_propertyName() == "isLoading") {
            if (!$find("ReportViewer").get_isLoading()) {
                adjustIframeSize();
            }
        }
    };
});

【问题讨论】:

标签: asp.net-mvc reportviewer ssrs-2008-r2


【解决方案1】:

使用ReportViewer for MVC 中的一组扩展解决了类似的问题。

@Html.ReportViewer(
   ViewBag.ReportViewer as Microsoft.Reporting.WebForms.ReportViewer, 
   new { scrolling = "no" })

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-25
    • 2013-03-15
    • 2012-04-22
    • 1970-01-01
    • 1970-01-01
    • 2011-03-17
    相关资源
    最近更新 更多