我有一个MVC项目,我正在尝试添加Telerik报告。我能够设置报告并进行设计,但是当我创建报告查看器时,我收到了错误消息。我已经尝试添加对Telerik dll的引用,将dll添加到bin中,为web.conifg添加了各种选项,但没有任何效果。你能帮我搞定一下吗?
创建报告后,我使用报告查看器向导添加了一个包含报告查看器的视图。我添加了一个新项目“Telerik MVC Report Viewer Page Q2 2015”,如下所述:http://www.telerik.com/help/reporting/mvc-report-viewer-extension-embedding.html
这创建了一个名为ReportViewerView1.cshtml的视图。问题是当我运行网站时,我在@(Html.TelerikReporting()。ReportViewer()上写错误
CS1061:'System.Web.Mvc.HtmlHelper'不包含 'TelerikReporting'的定义,没有扩展方法 'TelerikReporting'接受第一个类型的参数 可以找到'System.Web.Mvc.HtmlHelper'(你错过了吗? 使用指令或程序集引用?)
我尝试添加对各种dll的引用但没有成功。我找到了http://www.telerik.com/blogs/using-the-telerik-extensions-in-asp-net-mvc4-today---a-first-look和http://www.telerik.com/blogs/telerik-reporting-in-mvc-sure-it-takes-8-quick-steps-但是他们的步骤也没有用。我有一个使用报告查看器的旧asp.net(不是MVC)的同事,我复制了他的web.config元素,但这也没有帮助。
以下是报告查看器的视图:
@using ProjectName.Views
@{
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 TypeReportSource() { TypeName = "ProjectName.Reports.ShippingLabel, ProjectName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" })
// 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()
)
}
为以下文件设置了参考;所有这些都将copy local设置为true:
Telerik.Reporting
Telerik.Reporting.Services.WebApi
Telerik.Reporting.XpsRendering
Telerik.ReportViewer.Mvc
Telerik.ReportViewer.WebForms
我的bin文件夹包含以下文件:
Telerik.Reporting.Adomd.dll
Telerik.Reporting.Adomd.pdb
Telerik.Reporting.Adomd.xml
Telerik.Reporting.Cache.Database.dll
Telerik.Reporting.Cache.Database.pdb
Telerik.Reporting.Cache.Database.xml
Telerik.Reporting.Cache.StackExchangeRedis.dll
Telerik.Reporting.Cache.StackExchangeRedis.pdb
Telerik.Reporting.Cache.StackExchangeRedis.xml
Telerik.Reporting.dll
Telerik.Reporting.OpenXmlRendering.dll
Telerik.Reporting.OpenXmlRendering.pdb
Telerik.Reporting.OpenXmlRendering.xml
Telerik.Reporting.pdb
Telerik.Reporting.Service.dll
Telerik.Reporting.Service.pdb
Telerik.Reporting.Service.xml
Telerik.Reporting.Services.ServiceStack.dll
Telerik.Reporting.Services.ServiceStack.pdb
Telerik.Reporting.Services.ServiceStack.xml
Telerik.Reporting.Services.WebApi.dll
Telerik.Reporting.Services.WebApi.pdb
Telerik.Reporting.Services.WebApi.xml
Telerik.Reporting.xml
Telerik.Reporting.XpsRendering.dll
Telerik.Reporting.XpsRendering.pdb
Telerik.Reporting.XpsRendering.xml
Telerik.ReportViewer.Html5.WebForms.dll
Telerik.ReportViewer.Html5.WebForms.pdb
Telerik.ReportViewer.Html5.WebForms.xml
Telerik.ReportViewer.Mvc.dll
Telerik.ReportViewer.Mvc.pdb
Telerik.ReportViewer.Mvc.xml
Telerik.ReportViewer.Silverlight.dll
Telerik.ReportViewer.Silverlight.pdb
Telerik.ReportViewer.Silverlight.TextResources.resx
Telerik.ReportViewer.Silverlight.xml
Telerik.ReportViewer.WebForms.dll
Telerik.ReportViewer.WebForms.pdb
Telerik.ReportViewer.WebForms.Resources.resx
Telerik.ReportViewer.WebForms.xml
Telerik.ReportViewer.WinForms.dll
Telerik.ReportViewer.WinForms.pdb
Telerik.ReportViewer.WinForms.Resources.resx
Telerik.ReportViewer.WinForms.xml
Telerik.ReportViewer.Wpf.dll
Telerik.ReportViewer.Wpf.pdb
Telerik.ReportViewer.Wpf.TextResources.resx
Telerik.ReportViewer.Wpf.xml
我的web.config看起来像这样
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=152368
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<sectionGroup name="telerik">
<section name="webAssets" type="Telerik.Web.Mvc.Configuration.WebAssetConfigurationSection, Telerik.Web.Mvc" requirePermission="false"/>
</sectionGroup>
</configSections>
<connectionStrings>
*** Commented out ***
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="true" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="UploadLocation" value="/Attachments/"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="Telerik.ReportViewer.WebForms, Version=9.1.15.731, Culture=neutral, PublicKeyToken=a9d7983dfcc261be" />
<add assembly="Telerik.Reporting, Version=9.1.15.731, Culture=neutral, PublicKeyToken=a9d7983dfcc261be" />
</assemblies>
</compilation>
<pages>
<controls>
<add tagPrefix="telerik" namespace="Telerik.Web.UI" assembly="Telerik.Web.UI" />
</controls>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
<add namespace="Kendo.Mvc.UI" />
<add namespace="Telerik.Reporting" />
<add namespace="Telerik.ReportViewer" />
</namespaces>
</pages>
<httpHandlers>
<add type="Telerik.ReportViewer.WebForms.HttpHandler, Telerik.ReportViewer.WebForms, Version=9.1.15.731, Culture=neutral, PublicKeyToken=a9d7983dfcc261be" path="Telerik.ReportViewer.axd" verb="*" validate="true" />
</httpHandlers>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
<add name="Telerik.ReportViewer.axd_*" type="Telerik.ReportViewer.WebForms.HttpHandler, Telerik.ReportViewer.WebForms, Version=8.1.14.618, Culture=neutral, PublicKeyToken=a9d7983dfcc261be" path="Telerik.ReportViewer.axd" verb="*" preCondition="integratedMode" />
</handlers>
</system.webServer>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
答案 0 :(得分:1)
遇到同样的麻烦,我不得不将以下内容添加到剃须刀页面的顶部:
@using Telerik.ReportViewer.Mvc
@using Telerik.Reporting
我还将报告从MVC项目的根目录移到了views文件夹中 - 不确定这是否有帮助。
答案 1 :(得分:0)
如果您希望Razor识别Telerik命令,那么您应该将库引用添加到位于Views目录中的Web.config文件中(而不是主Web.config文件!)。
在这个文件中会有一个<system.web.webPages.razor>
部分 - 需要在这里添加命名空间,以便Razor可以使用它们:
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization"/>
<add namespace="System.Web.Routing" />
<add namespace="Telerik.Reporting" />
<add namespace="Telerik.ReportViewer.Mvc" />
</namespaces>
</pages>
答案 2 :(得分:0)
您要查找的扩展方法位于short
lib。添加对它的引用,不要忘记使用:
Telerik.ReportViewer.Mvc.dll
答案 3 :(得分:0)
我也有类似的问题,但我的更多与@RenderSections有关。如果你有部分telerikReportViewer控件,请确保将@section样式和@section脚本放在调用partial的父页面上。