【发布时间】:2017-02-22 23:16:42
【问题描述】:
我正在尝试使用 Telerik 报告框架构建报告系统。到目前为止,我已经能够使用 vs 设计器创建报告,但还没有设法将附件附加到任何类型的动态数据中。
我在 ASP.NET MVC 项目中执行此操作(不是 Telerik MVC 项目。这有关系吗?)。
我目前有:
- 使用报表查看器向导时自动创建的控制器
- 报告
- 我想用来填充报告的模型
这是我认为的代码:
@model Telerik.Reporting.ReportSource
@(Html.TelerikReporting().ReportViewer()
.Id("reportViewer1")
.ServiceUrl(Url.Content("~/api/reports"))
.ReportSource(model)
.ViewMode(ViewMode.Interactive)
.ScaleMode(ScaleMode.Specific)
.Scale(1.0)
.PersistSession(false)
.PrintMode(PrintMode.AutoSelect)
)
让我立即感到困惑的一件事是如何定义要获取的数据?
假设我有一个模型要用于填充报告:
public class ReportModel()
{
Dictionary<string, int> Graphdata;
public ReportModel()
{
Graphdata = GetGraphData();
}
public Dictionary<string, int> GetGraphData()
{
...
}
}
所以我会在 Reports 控制器中创建一个新报告:
var report = new Report1();
现在我必须为报告创建数据源。这就是我被困的地方......
报告的模型将包含报告中所有不同元素的多个列表、表格、字典。
在文档中,他们这样做:
// Creating and configuring the ObjectDataSource component:
var objectDataSource = new Telerik.Reporting.ObjectDataSource();
objectDataSource.DataSource = typeof(Products); // Specifying the business object type
objectDataSource.DataMember = "GetProducts"; // Specifying the name of the data object method
objectDataSource.CalculatedFields.Add(new Telerik.Reporting.CalculatedField("FullName", typeof(string), "=Fields.Name + ' ' + Fields.ProductNumber")); // Adding a sample calculated field.
// Specify the parameters, their types and values
objectDataSource.Parameters.Add(new Telerik.Reporting.ObjectDataSourceParameter("color", typeof(string), "Silver"));
objectDataSource.Parameters.Add(new Telerik.Reporting.ObjectDataSourceParameter("productModelID", typeof(int), 23));
这就是我迷路的地方。所以这是我的问题:
如果报表上有多个元素,是否必须为每个元素创建一个数据源?
将数据绑定到报表的正确 MVC 方法是什么?
如果reportviewer 是通过API 获取实际的报告,那么API 如何知道将创建报告对象时绑定的数据发送给它?
【问题讨论】:
标签: asp.net asp.net-mvc telerik telerik-reporting