我正在敲打砖头以使其工作。我有使用报表设计器生成的报表,它们工作正常,因为我已经使用iframe加载它们现在我想使用Html5报表查看器。但是在大多数教程中,他们使用的是trdx报告而不是使用报表设计器生成的报表。
我有一个名为XYZ.TelerikReports的类库,其中所有的reportname.cs(报告)文件都存在,我的主项目位于我要显示报告的同一个解决方案中。
$("#reportViewer1")
.telerik_ReportViewer({
serviceUrl: "/api/reports/",
templateUrl: '/ReportViewer/templates/telerikReportViewerTemplate.html',
reportSource: {
report: "XYZ.TelerikReports.IncomeStatementReport,XYZ.TelerikReports"
parameters: { ReportDataID: parseInt('@state.CurrentReportDataID') }
},
scale: "1.0"
});
现在我想知道我的serviceUrl应该是什么?
答案 0 :(得分:1)
serviceUrl期望路由到Telerik Reporting Web API控制器。您使用的当前值/api/reports/
是Telerik的此控制器的默认名称。该文档详细说明了如何很好地实现Web API控制器。您会在http://www.telerik.com/help/reporting/telerik-reporting-rest-host-http-service-using-web-hosting.html和此处http://www.telerik.com/help/reporting/telerik-reporting-rest-implementing-http-service.html找到。
如果报告名称是报告类或.trdx的名称,则此控制器将成功解析请求的报告。或者,您可以实施客户报告解析程序。这可以按照此处http://www.telerik.com/help/reporting/telerik-reporting-rest-custom-report-resolver.html文档中的说明完成。
所以你的serviceUrl很好。您只需要确保您拥有所谓的设置服务。
答案 1 :(得分:0)
一种可能的方法是修改报告API控制器以使用报告类型解析器并更改CreateReportResolver,例如。
protected override IReportResolver CreateReportResolver()
{
var reportsPath = HttpContext.Current.Server.MapPath("~/Reports");
return new ReportTypeResolver()
.AddFallbackResolver(new ReportFileResolver(reportsPath));
}
然后在HTML5查看器配置中指定每个报告的完全限定程序集名称或类名(正如您所做的那样)。 关于服务URL的路径,您可以使用上面的api / reports路由,但是您必须在WebApiConfig.Register函数中调用telerik报告路由注册功能,即:
ReportsControllerConfiguration.RegisterRoutes(GlobalConfiguration.Configuration);
这意味着您的报告API位于名为ReportsController的控制器中。
或者,您可以通过实现自己的报告路由注册功能并调用它而不是上面的代码片段来自定义/ Controllers / MyCustomReports之类的路径。例如,您可以:
private static void RegisterReportingRoutes(HttpConfiguration config)
{
config.Routes.MapHttpRoute(name: "Clients",
routeTemplate: "Controllers/{controller}/clients/{clientID}",
defaults: new { controller = "MyCustomReports", action = "Clients", clientID = RouteParameter.Optional });
config.Routes.MapHttpRoute(
name: "Instances",
routeTemplate: "Controllers/{controller}/clients/{clientID}/instances/{instanceID}",
defaults: new { controller = "MyCustomReports", action = "Instances", instanceID = RouteParameter.Optional });
config.Routes.MapHttpRoute(
name: "DocumentResources",
routeTemplate: "Controllers/{controller}/clients/{clientID}/instances/{instanceID}/documents/{documentID}/resources/{resourceID}",
defaults: new { controller = "MyCustomReports", action = "DocumentResources" });
config.Routes.MapHttpRoute(
name: "DocumentActions",
routeTemplate: "Controllers/{controller}/clients/{clientID}/instances/{instanceID}/documents/{documentID}/actions/{actionID}",
defaults: new { controller = "MyCustomReports", action = "DocumentActions" });
config.Routes.MapHttpRoute(
name: "DocumentPages",
routeTemplate: "Controllers/{controller}/clients/{clientID}/instances/{instanceID}/documents/{documentID}/pages/{pageNumber}",
defaults: new { controller = "MyCustomReports", action = "DocumentPages" });
config.Routes.MapHttpRoute(
name: "DocumentInfo",
routeTemplate: "Controllers/{controller}/clients/{clientID}/instances/{instanceID}/documents/{documentID}/info",
defaults: new { controller = "MyCustomReports", action = "DocumentInfo" });
config.Routes.MapHttpRoute(
name: "Documents",
routeTemplate: "Controllers/{controller}/clients/{clientID}/instances/{instanceID}/documents/{documentID}",
defaults: new { controller = "MyCustomReports", action = "Documents", documentID = RouteParameter.Optional });
config.Routes.MapHttpRoute(
name: "Parameters",
routeTemplate: "Controllers/{controller}/clients/{clientID}/parameters",
defaults: new { controller = "MyCustomReports", action = "Parameters" });
config.Routes.MapHttpRoute(
name: "Formats",
routeTemplate: "Controllers/{controller}/clients/{clientID}/formats",
defaults: new { controller = "MyCustomReports", action = "Formats" });
}
请注意,您应该从包含REST服务的解决方案中引用报告库。