在 MVC 4 中使用RDLC 报表

2023-10-31 15:38
文章标签 使用 mvc 报表 rdlc

本文主要是介绍在 MVC 4 中使用RDLC 报表,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

前期知识点

RDLC 报表

Visual Studio .NET进入2005版本以后,Crystal Report与IDE的结合更“紧密”了,至少我们看不到那个讨厌的注册窗口了。但是,Microsoft似乎并不容忍在自己的超级工具中竟然没有报表工具,于是Report Viewer Control出现了,我把它的报表称为RDLC报表

在VS .NET 2005之前,SQL Server Reporting Services中已经提供了一种被称为报表定义语言(Report Definition Language, RDL)的语言;在VS .NET 2005中,Microsoft提供了针对这种报表的设计器,并提供了在WinForm和WebForm中使用这种报表的能力。Microsoft将这种报表的后缀定为RDLC,RDL仍然是Report Definition Language的缩写,那么C代表什么呢?C代表Client-side processing,凸显了它的客户端处理能力。

这么写貌似有点长啊....简略点吧.不会RDLC的 先搞个C/S的WINDOS应用程序先练练手,教程百度.然后再搞个web winfrom 练练手,操作有点不一样.

把数据搞出来了,下面再接着干.


参考链接:

http://www.csdn123.com/html/itweb/20130813/57034_57018_57042.htm               http://www.cnblogs.com/devv/archive/2013/08/13/3255343.html
http://www.codeproject.com/Articles/609580/Prototype-MVC4-Razor-ReportViewer-RDLC
http://www.codeproject.com/Articles/609580/Prototype-MVC4-Razor-ReportViewer-RDLC
http://www.ekeol.com/forum/10612
http://www.cnblogs.com/wuhuacong/p/4109833.html
http://jingyan.baidu.com/article/ab69b270ff9c6e2ca7189f0e.html


步骤:

先新建一个项目 用ASP.NET Web 窗体应用程序 创建;然后将你希望完成的报表在里面实现如下图.


界面如图:


效果如下:




MVC4

在MVC4的项目才是我们的主项目,上面那个只是为了测试RDLC功能是否正常能用,否则在MVC4中直接搞,太麻烦了.

然后拷贝文件到MVC4中.如图所示 拷贝RDLC文件夹,拷贝WebForm1.aspx



剩下就是配置一些参数了.

直接运行看下报什么错,然后根据错误配置该配置的就好了. 一般根据需要配置下面俩个其中之一.具体看界面错误有提示的.



还有路由别忘记设置了.列外不能用MVC4的访问模式



效果如下:



本地测试通过了.别急放到服务器上还有一堆错误等着你呢!!!

错误记录我都已经记录如下,自己参考着解决.

解决一下错误需要做个前期工作

想查看一下SharePoint的Microsoft.SharePoint.Library.DLL, 可是发现这个文件被安装在了GAC中. 如何才能拿到这个DLL, 反汇编一下玩玩呢?GAC的目录在c:\windows\assembly, 而这个目录是不允许你直接复制粘贴的. 为了把文件拿出来, 你需要使用命令行.

如果你使用命令行的话, 你会发现GAC的目录结构与Windows Explorer展示给你的看的目录不同.

 要把文件从GAC中拿到, 你可以运行下面的命令:

C:\WINDOWS\assembly\GAC_MSIL>xcopy *.* C:\GACDLLs\ /s /r

具体程序集所在的目录也许会不同. 有可能是GAC 或者是GAC_32. 先找到你想要的文件, 然后你可能会需要从上面列出的文件夹中进行拷贝.

具体操作

win+r

cmd

cd C:\WINDOWS\assembly\GAC_MSIL>

xcopy *.* C:\GACDLLs\ /s /r


问:designer.cs 不自动生成

答:拷贝文件到MVC项目中选中文件,右键[转换为web应用程序]


问:错误 1 命名空间“Microsoft”中不存在类型或命名空间名称“Reporting”(是否缺少程序集引用?)E:\开发\装箱系统\Web_Up20151116\Web\AppPallet\AppPallet\RDLC\Default.aspx.designer.cs5733AppPallet

答:添加引用 Microsoft.ReportViewer.WebForms(引用前需要核对版本如图)




=========================发布错误=========================

Server Error in '/' Application.
--------------------------------------------------------------------------------


Configuration Error 
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. 


Parser Error Message: Could not load file or assembly 'Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. 系统找不到指定的文件。


Source Error: 




Line 27:   <system.web>
Line 28:     <httpHandlers>
Line 29:       <add verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" /> 
Line 30:     </httpHandlers>
Line 31:     <compilation targetFramework="4.0" />
 


Source File: E:\OA_Npp_Pro测试\web.config    Line: 29 


Assembly Load Trace: The following information can be helpful to determine why the assembly 'Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' could not be loaded.




WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].


 解决方案:
拷贝 C:\GACDLLs\Microsoft.ReportViewer.WebForms\11.0.0.0__89845dcd8080cc91 目录下的 Microsoft.ReportViewer.WebForms.dll  文件到网站发布bin目录下
 

=========================发布错误=========================

Could not load file or assembly 'Microsoft.ReportViewer.Common, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. 系统找不到指定的文件。 Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.ReportViewer.Common, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. 系统找不到指定的文件。Source Error: The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:1. Add a "Debug=true" directive at the top of the file that generated the error. Example:  <%@ Page Language="C#" Debug="true" %>or:2) Add the following section to the configuration file of your application:<configuration>   <system.web>       <compilation debug="true"/>   </system.web></configuration>Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.  Assembly Load Trace: The following information can be helpful to determine why the assembly 'Microsoft.ReportViewer.Common, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' could not be loaded.WRN: Assembly binding logging is turned OFF.To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.Note: There is some performance penalty associated with assembly bind failure logging.To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].Stack Trace: [FileNotFoundException: Could not load file or assembly 'Microsoft.ReportViewer.Common, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. 系统找不到指定的文件。]   Microsoft.Reporting.WebForms.LocalReport..ctor() +0   Microsoft.Reporting.WebForms.ReportHierarchy..ctor(ServerReport serverReport) +120   Microsoft.Reporting.WebForms.ReportViewer.CreateReportHierarchy() +51   Microsoft.Reporting.WebForms.ReportViewer..ctor() +281   ASP.webforms_webform1_aspx.__BuildControlReportViewer1() +33   ASP.webforms_webform1_aspx.__BuildControlform1() +999   ASP.webforms_webform1_aspx.__BuildControlTree(webforms_webform1_aspx __ctrl) +189   ASP.webforms_webform1_aspx.FrameworkInitialize() +29   System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +54   System.Web.UI.Page.ProcessRequest() +78   System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21   System.Web.UI.Page.ProcessRequest(HttpContext context) +49   ASP.webforms_webform1_aspx.ProcessRequest(HttpContext context) +4   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +100   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75--------------------------------------------------------------------------------Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.504 

解决方案:
拷贝 C:\GACDLLs\Microsoft.ReportViewer.Common\11.0.0.0__89845dcd8080cc91 下Microsoft.ReportViewer.Common.dll 到bin目录下即可


=========================发布错误=========================

An error occurred during local report processing.
The report definition for report 'Report1' has not been specified
Could not find file 'E:\OA_Npp_Pro测试\RDLC\Report1.rdlc'. 


解决方案:
拷贝Report1.rdlc'. 文件到 服务器 rdlc 目录下


=========================发布错误=========================

An error occurred during local report processing.
The definition of the report 'RDLC\Report1.rdlc' is invalid.
An unexpected error occurred in Report Processing.
Could not load file or assembly 'Microsoft.SqlServer.Types, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. 系统找不到指定的文件。 


解决方案:

拷贝 C:\GACDLLs\Microsoft.SqlServer.Types\11.0.0.0__89845dcd8080cc91 目录下 Microsoft.SqlServer.Types.dll  到服务器发布bin目录下


=========================发布错误=========================


An error occurred during local report processing.
The definition of the report 'RDLC\Report1.rdlc' is invalid.
An unexpected error occurred in Report Processing.
Could not load file or assembly 'Microsoft.ReportViewer.ProcessingObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. 系统找不到指定的文件。 


解决方案:

拷贝 C:\GACDLLs\Microsoft.ReportViewer.ProcessingObjectModel\11.0.0.0__89845dcd8080cc91 目录下 Microsoft.ReportViewer.ProcessingObjectModel.DLL 到发布目录bin 下




=========================发布错误=========================
Server Error in '/' Application.


Parser Error 
  Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 


 Parser Error Message: The file '/RDLC/Default.aspx.cs' does not exist.


Source Error: 



Line 1:  <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
Line 2:  
Line 3:  <%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>
  
 Source File:  /RDLC/Default.aspx    Line:  1 

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34280 



=========================发布错误=========================

Report Viewer Configuration Error 


The Report Viewer Web Control HTTP Handler has not been registered in the application's web.config file. Add <add verb="*" path="Reserved.ReportViewerWebControl.axd" type = "Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" /> to the system.web/httpHandlers section of the web.config file, or add <add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" /> to the system.webServer/handlers section for Internet Information Services 7 or later.


这篇关于在 MVC 4 中使用RDLC 报表的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/316363

相关文章

Java使用ANTLR4对Lua脚本语法校验详解

《Java使用ANTLR4对Lua脚本语法校验详解》ANTLR是一个强大的解析器生成器,用于读取、处理、执行或翻译结构化文本或二进制文件,下面就跟随小编一起看看Java如何使用ANTLR4对Lua脚本... 目录什么是ANTLR?第一个例子ANTLR4 的工作流程Lua脚本语法校验准备一个Lua Gramm

Java Optional的使用技巧与最佳实践

《JavaOptional的使用技巧与最佳实践》在Java中,Optional是用于优雅处理null的容器类,其核心目标是显式提醒开发者处理空值场景,避免NullPointerExce... 目录一、Optional 的核心用途二、使用技巧与最佳实践三、常见误区与反模式四、替代方案与扩展五、总结在 Java

使用Java将DOCX文档解析为Markdown文档的代码实现

《使用Java将DOCX文档解析为Markdown文档的代码实现》在现代文档处理中,Markdown(MD)因其简洁的语法和良好的可读性,逐渐成为开发者、技术写作者和内容创作者的首选格式,然而,许多文... 目录引言1. 工具和库介绍2. 安装依赖库3. 使用Apache POI解析DOCX文档4. 将解析

Qt中QUndoView控件的具体使用

《Qt中QUndoView控件的具体使用》QUndoView是Qt框架中用于可视化显示QUndoStack内容的控件,本文主要介绍了Qt中QUndoView控件的具体使用,具有一定的参考价值,感兴趣的... 目录引言一、QUndoView 的用途二、工作原理三、 如何与 QUnDOStack 配合使用四、自

C++使用printf语句实现进制转换的示例代码

《C++使用printf语句实现进制转换的示例代码》在C语言中,printf函数可以直接实现部分进制转换功能,通过格式说明符(formatspecifier)快速输出不同进制的数值,下面给大家分享C+... 目录一、printf 原生支持的进制转换1. 十进制、八进制、十六进制转换2. 显示进制前缀3. 指

使用Python构建一个Hexo博客发布工具

《使用Python构建一个Hexo博客发布工具》虽然Hexo的命令行工具非常强大,但对于日常的博客撰写和发布过程,我总觉得缺少一个直观的图形界面来简化操作,下面我们就来看看如何使用Python构建一个... 目录引言Hexo博客系统简介设计需求技术选择代码实现主框架界面设计核心功能实现1. 发布文章2. 加

shell编程之函数与数组的使用详解

《shell编程之函数与数组的使用详解》:本文主要介绍shell编程之函数与数组的使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录shell函数函数的用法俩个数求和系统资源监控并报警函数函数变量的作用范围函数的参数递归函数shell数组获取数组的长度读取某下的

使用Python开发一个带EPUB转换功能的Markdown编辑器

《使用Python开发一个带EPUB转换功能的Markdown编辑器》Markdown因其简单易用和强大的格式支持,成为了写作者、开发者及内容创作者的首选格式,本文将通过Python开发一个Markd... 目录应用概览代码结构与核心组件1. 初始化与布局 (__init__)2. 工具栏 (setup_t

Python虚拟环境终极(含PyCharm的使用教程)

《Python虚拟环境终极(含PyCharm的使用教程)》:本文主要介绍Python虚拟环境终极(含PyCharm的使用教程),具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,... 目录一、为什么需要虚拟环境?二、虚拟环境创建方式对比三、命令行创建虚拟环境(venv)3.1 基础命令3

Python Transformer 库安装配置及使用方法

《PythonTransformer库安装配置及使用方法》HuggingFaceTransformers是自然语言处理(NLP)领域最流行的开源库之一,支持基于Transformer架构的预训练模... 目录python 中的 Transformer 库及使用方法一、库的概述二、安装与配置三、基础使用:Pi