问题描述
ASP.NET MVC Telerik报表查看器未呈现。页面中生成的HTML代码是一个空div。
<div id="reportViewer1">
</div>
感谢断点和谷歌浏览器开发人员工具(网络标签)我知道从不调用报告REST服务(默认情况下在路径/ api / report中创建)。我也知道问题不是REST服务本身(在Global.asax中正确配置),因为我试图导航到/ api / reports并且api控制器中的断点被命中,它返回给我结果如下:
[{"name":"PDF","localizedName":"Acrobat (PDF) file"},{"name":"CSV","localizedName":"CSV (comma delimited)"},{"name":"XLS","localizedName":"Excel 97-2003"},{"name":"RTF","localizedName":"Rich Text Format"},{"name":"IMAGE","localizedName":"TIFF file"},{"name":"MHTML","localizedName":"Web Archive"},{"name":"XPS","localizedName":"XPS Document"}]
详情
我是Telerik报道的新手,我试图通过HTML5报表查看器的服务器端包装器在网页中显示报表。
这一点要明确:http://www.telerik.com/help/reporting/mvc-report-viewer-extension-overview.html
我使用了你可以在Add new item ---&gt;下找到的模板。 Telerik Report Viewer Page Q2 2015 ---&gt;样本报告定义
如果你知道模板,那么你可能知道它准备好使用Telerik报告查看器(对Telerik组件等的引用)和包含所有必要文件的文件夹所需的一切,包括一个名为SampleReport的示例报告.trdx对测试很有用。
然而,在我添加模板后,出现了以下页面
正如您所看到的,有一些警告,在下面您可以阅读模板创建的完整详细日志。要阅读的重要内容是警告:Telerik似乎使用某些.NET程序集的旧版本。
07/12/2015 10:38:51 Build Started
Check Framework Support
Assembly name is null: False
Assembly : Kendo.Mvc
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : Microsoft.CodeDom.Providers.DotNetCompilerPlatform
Assembly Version: 1.0.0.0
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : Microsoft.CSharp
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : System
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : System.Data
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : System.Drawing
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : System.Net.Http.Formatting
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : System.Web.DynamicData
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : System.Web.Entity
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : System.Web.ApplicationServices
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : System.ComponentModel.DataAnnotations
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : System.Core
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : System.Data.DataSetExtensions
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : System.Web.Http
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : System.Web.Http.WebHost
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : System.Xml.Linq
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : System.Web
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : System.Web.Extensions
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : System.Web.Abstractions
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : System.Web.Routing
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : System.Xml
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : System.Configuration
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : System.Web.Services
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : System.EnterpriseServices
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : Microsoft.Web.Infrastructure
Assembly Version: 1.0.0.0
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : System.Net.Http
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : System.Net.Http.WebRequest
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : System.Web.Helpers
Assembly Version: 3.0.0.0
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : System.Web.Mvc
Assembly Version: 5.2.3.0
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : System.Web.Optimization
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : System.Web.Razor
Assembly Version: 3.0.0.0
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : System.Web.WebPages
Assembly Version: 3.0.0.0
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : System.Web.WebPages.Deployment
Assembly Version: 3.0.0.0
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : System.Web.WebPages.Razor
Assembly Version: 3.0.0.0
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : Telerik.Reporting
Assembly Version: 9.1.15.731
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : Telerik.Reporting.Services.WebApi
Assembly Version: 9.1.15.731
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : Telerik.Reporting.XpsRendering
Assembly Version: 9.1.15.731
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : Telerik.ReportViewer.Mvc
Assembly Version: 9.1.15.731
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : WebGrease
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : Antlr3.Runtime
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : Newtonsoft.Json
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : EntityFramework
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : EntityFramework.SqlServer
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : Microsoft.AspNet.Identity.Core
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : Microsoft.AspNet.Identity.Owin
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : Microsoft.AspNet.Identity.EntityFramework
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : Owin
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : Microsoft.Owin
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : Microsoft.Owin.Host.SystemWeb
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : Microsoft.Owin.Security
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : Microsoft.Owin.Security.Facebook
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : Microsoft.Owin.Security.Cookies
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : Microsoft.Owin.Security.OAuth
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : Microsoft.Owin.Security.Google
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : Microsoft.Owin.Security.Twitter
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Assembly name is null: False
Assembly : Microsoft.Owin.Security.MicrosoftAccount
Assembly Version:
Product Version: 9.1.15.731
Verify Telerik Reporting Version: True
Build Completed
Cancel the form closing: False
Add project references
Get project references.
Reference already available: Telerik.ReportViewer.Mvc, Version=9.1.15.731, Culture=neutral, PublicKeyToken=a9d7983dfcc261be
Add required references.
Add project references
Get project references.
Reference already available: Telerik.Reporting, Version=9.1.15.731, Culture=neutral, PublicKeyToken=a9d7983dfcc261be
Reference already available: Telerik.Reporting.Services.WebApi, Culture=neutral, Version=9.1.15.731, PublicKeyToken=a9d7983dfcc261be
Reference already available: Telerik.Reporting.XpsRendering, Version=9.1.15.731, Culture=neutral, PublicKeyToken=a9d7983dfcc261be
Verify Microsoft.AspNet.WebApi.WebHost package references
Is System.Web.Http.WebHost reference version compatible. Current: 4.0.0.0 | Required 4.0.0.0
Verify Microsoft.Web.Infrastructure package references
Is Microsoft.Web.Infrastructure reference version compatible. Current: 1.0.0.0 | Required 1.0.0.0
Verify Microsoft.AspNet.WebApi.Core package references
Is System.Web.Http reference version compatible. Current: 4.0.0.0 | Required 4.0.0.0
Verify Microsoft.AspNet.WebApi.Client package references
Is System.Net.Http.Formatting reference version compatible. Current: 4.0.0.0 | Required 4.0.0.0
Verify Microsoft.Net.Http package references
Is System.Net.Http reference version compatible. Current: 4.0.0.0 | Required 2.0.0.0
Warning: The referenced System.Net.Http assembly version is newer. You should add the following binding redirect:
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="31BF3856AD364E35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
For more information see: Assembly Binding Redirection MSDN article
Is System.Net.Http.WebRequest reference version compatible. Current: 4.0.0.0 | Required 2.0.0.0
Warning: The referenced System.Net.Http.WebRequest assembly version is newer. You should add the following binding redirect:
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.WebRequest" publicKeyToken="31BF3856AD364E35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
For more information see: Assembly Binding Redirection MSDN article
Verify Newtonsoft.Json package references
Is Newtonsoft.Json reference version compatible. Current: 6.0.0.0 | Required 4.5.0.0
Warning: The referenced Newtonsoft.Json assembly version is newer. You should add the following binding redirect:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
For more information see: Assembly Binding Redirection MSDN article
Enhance Global.asax: Global.asax.cs
Namespace Kind: vsCMElementNamespace
Class Kind: vsCMElementClass
Class Name MvcApplication
Class derives from System.Web.HttpApplication
Function Kind: vsCMElementFunction
Function name Application_Start
Function full name WebApplication3.MvcApplication.Application_Start
Namespace Kind: vsCMElementNamespace
Import System.Web.Http is available
'using System.Web.Http' statement is already available.
Namespace Kind: vsCMElementNamespace
Import Telerik.Reporting.Services.WebApi is available
'using Telerik.Reporting.Services.WebApi' statement is already available.
Register routes
Is REST Report Service route registered: True
Class with name ReportsController is found
Adding TelerikViewerPage.cshtml.Type project item
Adding TelerikViewerPage.cshtml.Trdx project item
Added prova.cshtml
Adding telerikReportViewer-9.1.15.731.min.js project item
Adding telerikReportViewer-9.1.15.731.css project item
Adding telerikReportViewerTemplate-9.1.15.731.html project item
Adding SampleReport.trdx project item
Added SampleReport.trdx
Adding ReportsController.cs project item
因此,正如警告所示,我在web.config文件中添加了以下行(在assemblyBinding部分中)。
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="31BF3856AD364E35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.WebRequest" publicKeyToken="31BF3856AD364E35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
但是,报表查看器未正确呈现:HTML帮助程序仅创建并清空div
<div id="reportViewer1">
</div>
我无法理解这是什么问题,如果有人能给我一个建议,那就太好了。
下面你可以看到我的剃刀页面的代码,其中包含报表查看器的定义(它是默认的,由模板生成)
@using WebApplication3.Views.Home
@using Telerik.ReportViewer.Mvc
@using Telerik.Reporting
@{
ViewBag.Title = "Telerik MVC HTML5 Report Viewer";
}
@section styles
{
<link href="http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet" />
<link href="http://cdn.kendostatic.com/2013.2.918/styles/kendo.common.min.css" rel="stylesheet" />
<link href="http://cdn.kendostatic.com/2013.2.918/styles/kendo.blueopal.min.css" rel="stylesheet" />
<style>
#reportViewer1 {
position: absolute;
left: 5px;
right: 5px;
top: 5px;
bottom: 5px;
overflow: hidden;
font-family: Verdana, Arial;
}
</style>
<link href="@Url.Content("~/ReportViewer/styles/telerikReportViewer-9.1.15.731.css")" rel="stylesheet" />
}
@(Html.TelerikReporting().ReportViewer()
// Each report viewer must have an id - it will be used by the initialization script
// to find the element and initialize the report viewer.
.Id("reportViewer1")
// The URL of the service which will serve reports.
// The URL corresponds to the name of the controller class (ReportsController).
// For more information on how to configure the service please check http://www.telerik.com/help/reporting/telerik-reporting-rest-conception.html.
.ServiceUrl(Url.Content("~/api/reports/"))
// The URL for the report viewer template. The template can be edited -
// new functionalities can be added and unneeded ones can be removed.
// For more information please check http://www.telerik.com/help/reporting/html5-report-viewer-templates.html.
.TemplateUrl(Url.Content("~/ReportViewer/templates/telerikReportViewerTemplate-9.1.15.731.html"))
// Strongly typed ReportSource - TypeReportSource or UriReportSource.
.ReportSource(new UriReportSource() { Uri = "Reports/SampleReport.trdx" })
// Specifies whether the viewer is in interactive or print preview mode.
// PrintPreview - Displays the paginated report as if it is printed on paper. Interactivity is not enabled.
// Interactive - Displays the report in its original width and height with no paging. Additionally interactivity is enabled.
.ViewMode(ViewMode.Interactive)
// Sets the scale mode of the viewer.
// Three modes exist currently:
// FitPage - The whole report will fit on the page (will zoom in or out), regardless of its width and height.
// FitPageWidth - The report will be zoomed in or out so that the width of the screen and the width of the report match.
// Specific - Uses the scale to zoom in and out the report.
.ScaleMode(ScaleMode.Specific)
// Zoom in and out the report using the scale
// 1.0 is equal to 100%, i.e. the original size of the report
.Scale(1.0)
// Sets whether the viewer’s client session to be persisted between the page’s refreshes(ex. postback).
// The session is stored in the browser’s sessionStorage and is available for the duration of the page session.
.PersistSession(false)
// Sets the print mode of the viewer.
.PrintMode(PrintMode.AutoSelect)
// Defers the script initialization statement. Check the scripts section below -
// each deferred script will be rendered at the place of TelerikReporting().DeferredScripts().
.Deferred()
.ClientEvents(
events => events
.RenderingBegin("onRenderingBegin")
.RenderingEnd("onRenderingEnd")
.PrintBegin("onPrintBegin")
.PrintEnd("onPrintEnd")
.ExportBegin("onExportBegin")
.ExportEnd("onExportBegin")
.UpdateUi("onUpdateUi")
.PageReady("onPageReady")
.Error("onError")
)
// Uncomment the code below to see the custom parameter editors in action
//.ParameterEditors(
// editors => editors
// .SingleSelectEditor("createSingleSelectEditor")
// .CustomEditors(new CustomParameterEditor
// {
// MatchFunction = "customMatch",
// CreateEditorFunction = "createCustomEditor"
// })
//)
)
@section scripts
{
<script src="@Url.Content("~/ReportViewer/js/telerikReportViewer-9.1.15.731.min.js")"></script>
<!--kendo.all.min.js can be used as well instead of kendo.web.min.js and kendo.mobile.min.js-->
<script src="http://cdn.kendostatic.com/2013.2.918/js/kendo.web.min.js"></script>
<!--kendo.mobile.min.js - optional, if gestures/touch support is required-->
<script src="http://cdn.kendostatic.com/2013.2.918/js/kendo.mobile.min.js"></script>
<script>
function onRenderingBegin() {
console.log("rendering begin!");
}
function onRenderingEnd() {
console.log("rendering end!");
}
function onPrintBegin() {
console.log("print begin!");
}
function onPrintEnd() {
console.log("print end!");
}
function onExportBegin() {
console.log("export begin!");
}
function onExportEnd() {
console.log("export end!");
}
function onUpdateUi() {
console.log("update ui!");
}
function onError() {
console.log("error!");
}
function onPageReady() {
console.log("page ready!");
}
function createSingleSelectEditor(placeholder, options) {
var dropDownElement = $(placeholder).html('<div></div>');
var parameter,
valueChangedCallback = options.parameterChanged,
dropDownList;
function onChange() {
var val = dropDownList.value();
valueChangedCallback(parameter, val);
}
return {
beginEdit: function (param) {
parameter = param;
$(dropDownElement).kendoDropDownList({
dataTextField: "name",
dataValueField: "value",
value: parameter.value,
dataSource: parameter.availableValues,
change: onChange
});
dropDownList = $(dropDownElement).data("kendoDropDownList");
}
};
}
function customMatch(parameter) {
return Boolean(parameter.availableValues)
&& !parameter.multivalue
&& parameter.type === telerikReportViewer.ParameterTypes.BOOLEAN;
}
function createCustomEditor(placeholder, options) {
var dropDownElement = $(placeholder).html('<div></div>');
var parameter,
valueChangedCallback = options.parameterChanged,
dropDownList;
function onChange() {
var val = dropDownList.value();
valueChangedCallback(parameter, val);
}
return {
beginEdit: function (param) {
parameter = param;
$(dropDownElement).kendoDropDownList({
dataTextField: "name",
dataValueField: "value",
value: parameter.value,
dataSource: parameter.availableValues,
change: onChange
});
dropDownList = $(dropDownElement).data("kendoDropDownList");
}
};
}
</script>
@(
// All deferred initialization statements will be rendered here
Html.TelerikReporting().DeferredScripts()
)
}
下面是REST服务的代码
public class ReportsController : ReportsControllerBase
{
static ReportServiceConfiguration configurationInstance;
static ReportsController()
{
//This is the folder that contains the XML (trdx) report definitions
//In this case this is the app folder
var reportsPath = HttpContext.Current.Server.MapPath("~/");
//Add resolver for trdx report definitions,
//then add resolver for class report definitions as fallback resolver;
//finally create the resolver and use it in the ReportServiceConfiguration instance.
var resolver = new ReportFileResolver(reportsPath)
.AddFallbackResolver(new ReportTypeResolver());
//Setup the ReportServiceConfiguration
configurationInstance = new ReportServiceConfiguration
{
HostAppId = "MvcApp",
Storage = new FileStorage(),
ReportResolver = resolver,
// ReportSharingTimeout = 0,
// ClientSessionTimeout = 15,
};
}
public ReportsController()
{
//Initialize the service configuration
this.ReportServiceConfiguration = configurationInstance;
}
}
这里是文件夹树的打印屏幕。 Prova.cshtml是包含报告查看器的文件。
prova.cshtml用于索引页面
@Html.Partial("prova")
...在索引页面中找到空div。