2014-11-17 111 views
0

我正在對着磚頭猛敲我的頭,讓這個工作。我有使用報表設計器生成的報表,它們工作正常,因爲我已經使用iframe加載它們,現在我想使用Html5報表查看器。但在大多數教程中,他們使用的是trdx報告,而不是使用報告設計器生成的報告。Telerik報告沒有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?

回答

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很好。你只需要確保你有它所稱的設置服務。

0

一種可能的方法是修改報告API控制器以使用報告類型解析器並更改CreateReportResolver(例如,

protected override IReportResolver CreateReportResolver() 
     { 
      var reportsPath = HttpContext.Current.Server.MapPath("~/Reports"); 

      return new ReportTypeResolver() 
          .AddFallbackResolver(new ReportFileResolver(reportsPath)); 
     } 

然後指定完全限定程序集名稱,或在HTML5瀏覽器配置每個報告的類名(因爲你已經這樣做)。 至於爲服務URL路徑,你可以用你上面的API /報告路線,但你必須調用Telerik的你WebApiConfig.Register功能報告路線登記功能,即:

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服務的解決方案中引用報告庫。