加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – MVC中的SSRS Reportviewer,通过自动调整iframe以

发布时间:2020-12-16 09:40:42 所属栏目:asp.Net 来源:网络整理
导读:在iframe中呈现reportviewer时,我已经拼凑了有关消除iframe滚动条的信息,转而使用浏览器滚动条. MVC不支持在视图中呈现报表查看器,因此需要iframe. 编辑:我努力找到这个解决方案(下面),因此我想我会分享. 在aspx页面(将在iframe中呈现的页面) $(function ()
在iframe中呈现reportviewer时,我已经拼凑了有关消除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();
            }
        }
    };
});

解决方法

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读