怎样创建一个MVC Telerik Reporting项目(二)
接上“怎样创建一个MVC Telerik Reporting项目(一)”
step4:在App_Start下添加一个WebApiConfig.cs文件,源码如下:
关于WebApiConfig的知识,后续有时间再另写一篇来详细讲解一下。
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Web.Http; 5 6 namespace ReportingDemo 7 { 8 public static class WebApiConfig 9 { 10 public static void Register(HttpConfiguration config) 11 { 12 config.Routes.MapHttpRoute( 13 name: "DefaultApi", 14 routeTemplate: "api/{controller}/{id}", 15 defaults: new { id = RouteParameter.Optional } 16 ); 17 18 Telerik.Reporting.Services.WebApi.ReportsControllerConfiguration.RegisterRoutes(config); 19 } 20 } 21 }

WebApiConfig.Register(GlobalConfiguration.Configuration); 复制到Global.asax文件中,引用命名空间:using System.Web.Http;

step5: 在Controllers下新建ReportsController.cs
1 namespace ReportingDemo.Controllers 2 { 3 using System.IO; 4 using System.Web; 5 using Telerik.Reporting.Cache.File; 6 using Telerik.Reporting.Services; 7 using Telerik.Reporting.Services.Engine; 8 using Telerik.Reporting.Services.WebApi; 9 10 public class ReportsController : ReportsControllerBase 11 { 12 static ReportServiceConfiguration preservedConfiguration; 13 14 static IReportServiceConfiguration PreservedConfiguration 15 { 16 get 17 { 18 if (null == preservedConfiguration) 19 { 20 preservedConfiguration = new ReportServiceConfiguration 21 { 22 HostAppId = "ReportDemo", 23 Storage = new FileStorage(), 24 ReportResolver = CreateResolver(), 25 // ReportSharingTimeout = 0, 26 // ClientSessionTimeout = 15, 27 }; 28 } 29 return preservedConfiguration; 30 } 31 } 32 33 public ReportsController() 34 { 35 this.ReportServiceConfiguration = PreservedConfiguration; 36 } 37 38 static IReportResolver CreateResolver() 39 { 40 var appPath = HttpContext.Current.Server.MapPath("~/"); 41 var reportsPath = Path.Combine(appPath, @"..\..\..\Report Designer\Examples"); 42 43 return new ReportFileResolver(reportsPath) 44 .AddFallbackResolver(new ReportTypeResolver()); 45 } 46 } 47 }

欢迎加入Telerik Reporting QQ群学习交流:472101663

浙公网安备 33010602011771号