专业的编程技术博客社区

网站首页 > 博客文章 正文

如何在MVC中将ActiveReports后台参数传递给前台

baijin 2024-12-25 09:59:17 博客文章 9 ℃ 0 评论

程序中的参数传递问题,使我们设计程序时,最常遇到的问题。本文主要讲解,如何通过后台为 ActiveReports报表参数赋值,并传递给前台页面元素。

开发环境

VS2013 + MVC4.0 + ActiveReports10

实现步骤:

1. 创建工程

在 Visual Studio 2013 中创建 MVC Web 项目

2. 创建 Web 服务文件

添加服务,在工程中添加一个【Web 服务】,然后切换到代码视图,修改该类继承的原始类型为 GrapeCity.ActiveReports.Web.ReportService

代码:

public class WebService1 :GrapeCity.ActiveReports.Web.ReportService

{

protected override object OnCreateReportHandler(string reportPath)

{
PageReport definition1 = (PageReport)base.OnCreateReportHandler(reportPath);

//definition1.Report.ReportParameters[0].DefaultValue.Values[0].ToString();

return definition1;

}

}

3. 添加 RDL 报表,并设置为运行时数据源

3.1 为报表添加参数,设置默认值

3.2 为报表绑定动态时数据源

添加字段:

绑定到数据控件中:

4. 在 Web 服务文件中实现 LocateDocument 方法

private void Document_LocateDataSource(object sender, LocateDataSourceEventArgs args)

{

DataTable dt = new DataTable();

dt.Columns.Add("Field1",typeof(int));

dt.Columns.Add("Field2");

dt.Columns.Add("Field3");

dt.Rows.Add(1,"test","test1");

dt.Rows.Add(2, "test", "test1");

dt.Rows.Add(2, "test", "test1");

string temp=args.Report.Parameters[0].CurrentValue.ToString();

args.Data = dt;

}

5. 在 Index 页面中添加 HTML5Viewer,并修改服务文件的 URL

var viewer = GrapeCity.ActiveReports.Viewer({

element: '#viewerContainer',

reportService: {

url: '/WebService1.asmx'

},

uiType: 'desktop',

report: {id:"RdlReport1.rdlx"},

localeUri: 'Scripts/en.txt',

error: function (error) {

console.log("error");

}

});

6. 调用 reportLoaded 方法

打开 RouteConfig.cs 文件,添加以下内容:

routes.IgnoreRoute("{*allActiveReport}", new { allActiveReport = @".*\.ar10(/.*)?" }); routes.IgnoreRoute("WebService1.asmx/{*pathInfo}");

以上就是实现在 MVC 中将 ActiveReports 后台参数传递给前台的具体方法了。

了解更多

参加视频会议,更快掌握ActiveReports报表工具!资深产品经理将详解 ActiveReports 报表功能、实操案例、技术资源等,您还可携带实际项目场景,和产品经理直接沟通,更快评估试用。

报名视频会议:http://www.gcpowertools.com.cn/products/webinars.aspx

快人一步,免费试用

请通过以下方式联系葡萄城,获取 ActiveReports 的免费试用版:

微信:GrapeCityDT

邮件:marketing.xa@grapecity.com

官网:www.gcpowertools.com.cn

关于葡萄城控件

葡萄城是一家跨国软件研发集团,专注控件领域近30年,是全球最大的控件提供商,也是微软认证的金牌合作伙伴。

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表