在 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

相关文章

从零教你安装pytorch并在pycharm中使用

《从零教你安装pytorch并在pycharm中使用》本文详细介绍了如何使用Anaconda包管理工具创建虚拟环境,并安装CUDA加速平台和PyTorch库,同时在PyCharm中配置和使用PyTor... 目录背景介绍安装Anaconda安装CUDA安装pytorch报错解决——fbgemm.dll连接p

Vue项目的甘特图组件之dhtmlx-gantt使用教程和实现效果展示(推荐)

《Vue项目的甘特图组件之dhtmlx-gantt使用教程和实现效果展示(推荐)》文章介绍了如何使用dhtmlx-gantt组件来实现公司的甘特图需求,并提供了一个简单的Vue组件示例,文章还分享了一... 目录一、首先 npm 安装插件二、创建一个vue组件三、业务页面内 引用自定义组件:四、dhtmlx

使用Python创建一个能够筛选文件的PDF合并工具

《使用Python创建一个能够筛选文件的PDF合并工具》这篇文章主要为大家详细介绍了如何使用Python创建一个能够筛选文件的PDF合并工具,文中的示例代码讲解详细,感兴趣的小伙伴可以了解下... 目录背景主要功能全部代码代码解析1. 初始化 wx.Frame 窗口2. 创建工具栏3. 创建布局和界面控件4

一文详解如何在Python中使用Requests库

《一文详解如何在Python中使用Requests库》:本文主要介绍如何在Python中使用Requests库的相关资料,Requests库是Python中常用的第三方库,用于简化HTTP请求的发... 目录前言1. 安装Requests库2. 发起GET请求3. 发送带有查询参数的GET请求4. 发起PO

Java中的Cursor使用详解

《Java中的Cursor使用详解》本文介绍了Java中的Cursor接口及其在大数据集处理中的优势,包括逐行读取、分页处理、流控制、动态改变查询、并发控制和减少网络流量等,感兴趣的朋友一起看看吧... 最近看代码,有一段代码涉及到Cursor,感觉写法挺有意思的。注意是Cursor,而不是Consumer

Node.js net模块的使用示例

《Node.jsnet模块的使用示例》本文主要介绍了Node.jsnet模块的使用示例,net模块支持TCP通信,处理TCP连接和数据传输,具有一定的参考价值,感兴趣的可以了解一下... 目录简介引入 net 模块核心概念TCP (传输控制协议)Socket服务器TCP 服务器创建基本服务器服务器配置选项服

如何使用CSS3实现波浪式图片墙

《如何使用CSS3实现波浪式图片墙》:本文主要介绍了如何使用CSS3的transform属性和动画技巧实现波浪式图片墙,通过设置图片的垂直偏移量,并使用动画使其周期性地改变位置,可以创建出动态且具有波浪效果的图片墙,同时,还强调了响应式设计的重要性,以确保图片墙在不同设备上都能良好显示,详细内容请阅读本文,希望能对你有所帮助...

Rust中的注释使用解读

《Rust中的注释使用解读》本文介绍了Rust中的行注释、块注释和文档注释的使用方法,通过示例展示了如何在实际代码中应用这些注释,以提高代码的可读性和可维护性... 目录Rust 中的注释使用指南1. 行注释示例:行注释2. 块注释示例:块注释3. 文档注释示例:文档注释4. 综合示例总结Rust 中的注释

Linux使用cut进行文本提取的操作方法

《Linux使用cut进行文本提取的操作方法》Linux中的cut命令是一个命令行实用程序,用于从文件或标准输入中提取文本行的部分,本文给大家介绍了Linux使用cut进行文本提取的操作方法,文中有详... 目录简介基础语法常用选项范围选择示例用法-f:字段选择-d:分隔符-c:字符选择-b:字节选择--c

使用Go语言开发一个命令行文件管理工具

《使用Go语言开发一个命令行文件管理工具》这篇文章主要为大家详细介绍了如何使用Go语言开发一款命令行文件管理工具,支持批量重命名,删除,创建,移动文件,需要的小伙伴可以了解下... 目录一、工具功能一览二、核心代码解析1. 主程序结构2. 批量重命名3. 批量删除4. 创建文件/目录5. 批量移动三、如何安