有没有办法在asp.net核心网页上显示RDLC Local ReportViewer控件?
要在传统的WebForms应用程序上显示ReportViewer,以下代码可以正常工作.
<body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <div style="height: 600px;"> <rsweb:ReportViewer ID="reportViewer" runat="server" Width="100%" Height="100%"></rsweb:ReportViewer> </div> </form> </body>
我已经尝试并测试了以下组件.结果如下.
> ReportViewerForMvc – 适用于MVC,但与ASPNET Core不兼容.
> MvcReportViewer – 适用于MVC,但与ASPNET Core不兼容(请参阅本期:https://github.com/ilich/MvcReportViewer/issues/121).
> MvcReportViewer – 不使用microsoft viewer控件,因此支持aspnet核心,但不适用于本地报告(需要报告服务器URL).
> ngx-ssrs-reportviewer npm package – 远程报告的包装器,不支持本地报告.(需要报告服务器URL)
Q1.什么是最好的使用方法< rsweb:ReportViewer>在asp.net核心应用程序?
解决方法
如果问题是如何在aspnet核心项目上使用Microsoft Reportviewer,无论实现细节如何,我的解决方案是绕过实际的reportviewer控件并直接将报表呈现给PDF或Excel.
它适用于.net Core 1.1.我们使用的Nuget包是Fornax的Microsoft Report Viewer 2012 Runtime.
它适用于.net Core 1.1.我们使用的Nuget包是Fornax的Microsoft Report Viewer 2012 Runtime.
using System.IO; using Microsoft.AspNetCore.Mvc; using Microsoft.Reporting.WebForms; namespace WebApplication3.Controllers { public class ReportController : Controller { private readonly IHostingEnvironment environment = null; public ReportController(IHostingEnvironment environment) { this.environment = environment; } public IActionResult Report() { string mimeType; string encoding; string filenameExtension; string[] streams; Warning[] warnings; var rv = new ReportViewer(); rv.ProcessingMode = ProcessingMode.Local; rv.LocalReport.ReportPath = Path.Combine(environment.ContentRootPath,"Reports","Report1.rdlc"); rv.LocalReport.Refresh(); var bytes = rv.LocalReport.Render("PDF",null,out mimeType,out encoding,out filenameExtension,out streams,out warnings); return File(bytes,mimeType); } }
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。