如何使活动报告Web查看在ASP.NET MVC [英] How to render Active Reports WebViewer in ASP.NET MVC

查看:321
本文介绍了如何使活动报告Web查看在ASP.NET MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天早些时候要求在DataDynamics论坛这个问题。我想,也许我会得到某种回应在这里左右。

I asked this question in the DataDynamics forum earlier today. I thought that maybe I'd get some sort of response here at SO.

我想获得WebViewer中了,在我的ASP.NET MVC应用程序中运行。
我试图使Web查看控制器(webViewer.RenderControl(HtmlTextWriter的),然后把结果放到ViewData的和我的观点。我不'知道如果这是正确的方式去了解这一点。任何帮助显示报告将大大AP preciated。

I am trying to get the WebViewer up and running in my ASP.NET MVC application. I am attempting to render the webviewer in the controller (webViewer.RenderControl(htmlTextWriter) and then put the results into ViewData and display the report in my view. I dont' even know if this is the correct way to go about this. Any help would be greatly appreciated.

控制器code:

	public ActionResult Display()
	{

		CurrentReport = new DetailedReport { ReportData = new DetailedData() { Repository = _repository } };

		var webViewer = new WebViewer();
		CurrentReport.Run();
		webViewer.ID = "WebViewer1";
		webViewer.Visible = true;
		webViewer.ViewerType = ViewerType.HtmlViewer;
		webViewer.Width = Unit.Percentage(100);
		webViewer.Report = CurrentReport;


		var stringWriter = new StringWriter();
		var htmlTextWriter = new HtmlTextWriter(stringWriter);
		webViewer.RenderBeginTag(htmlTextWriter);
		webViewer.RenderControl(htmlTextWriter);
		webViewer.RenderEndTag(htmlTextWriter);

		ViewData["WebViewer"] = stringWriter.ToString();

		return View();
	}

Display.aspx code:

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Register assembly="ActiveReports.Web, Version=5.2.1013.2, Culture=neutral, PublicKeyToken=cc4967777c49a3ff" namespace="DataDynamics.ActiveReports.Web" tagprefix="ActiveReportsWeb" %>
<%@ Import Namespace="xxxx.Core"%>

<asp:Content ID="Content1" ContentPlaceHolderID="ClientAdminContent" runat="server">
    <%=ViewData["WebViewer"] %>
</asp:Content>

错误:

对象引用未设置到对象的实例。
说明:执行当前Web请求的执行过程中发生未处理的异常。请查看有关错误的详细信息的堆栈跟踪以及它起源于code。

Object reference not set to an instance of an object. 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.

异常详细信息:System.NullReferenceException:未将对象引用设置到对象的实例

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

源错误:

60号线:VAR的HtmlTextWriter =新的HtmlTextWriter(StringWriter的);
61号线:webViewer.RenderBeginTag(HtmlTextWriter的);
行62:webViewer.RenderControl(HtmlTextWriter的);
63号线:webViewer.RenderEndTag(HtmlTextWriter的);
64号线:

Line 60: var htmlTextWriter = new HtmlTextWriter(stringWriter); Line 61: webViewer.RenderBeginTag(htmlTextWriter); Line 62: webViewer.RenderControl(htmlTextWriter); Line 63: webViewer.RenderEndTag(htmlTextWriter); Line 64:

源文件:C:\\项目\\ XXXX \\ XXXX \\程序\\ xxxx.Web.Controllers \\ ReportsController.cs行:62

Source File: C:\Projects\xxxx\xxxx\app\xxxx.Web.Controllers\ReportsController.cs Line: 62

**更新:**

	public ActionResult Display()
	{
		ViewData["Report"] = new DetailedReport { ReportData = new DetailedReport { ReportData = new DetailedData() { Repository = _repository } };
		return View();
	}

和我的看法是这样的:(我有文件后面没有code代表我的观点)

And my view looks like this: (I have no code behind files for my views).

<%
	var report = (ActiveReport3) ViewData["Report"];
	report.Run();
	WebViewer1.Report = report;
%>
<ActiveReportsWeb:WebViewer ID="WebViewer1" runat="server" Height="100%" Width="100%" ViewerType="AcrobatReader" />

我看着它经过调试,似乎通过细节部分正确步骤,把值到我的领域。但是,所有完成后,我得到消息的没有报表中指定。我希望,我真的没有使用codebehind文件放在我的看法,因为我不是使用这些其他地方。我也调试验证report.Document.Pages.Count> 0,我已经把code座上方和Web查看器控件下方(不认为真正的问题)。任何其他的想法?

I watch it go through debugger, and it seems to correctly step through the Details section, putting values into my fields. But after all is done, I get the message "No Report Specified." I'm hoping that I really don't have to use a codebehind file on my view because I'm not using them anywhere else. I have also debugged to verify that report.Document.Pages.Count > 0. I have put the code block both above and below the WebViewer control (don't think that really matters). Any additional thoughts?

**更新#2:**

我最终使用的答案在这里找到: http://stackoverflow.com/questions/566902<

I ended up using the answer found here: http://stackoverflow.com/questions/566902<

推荐答案

我们已经在内部研究了这一点,并找到了以下解决方案。您可以正常WebViewer中添加到视图。有没有必要在你的榜样复杂的低层次的互动code。相反,刚Web查看添加到您的ASPX视图正常。在我们的样本中添加的Web查看如下:

We have investigated this internally and found the following solution. You can add the WebViewer to a View normally. There is no need for the complicated low-level interaction code in your example. Instead, just add the WebViewer to your aspx view normally. In our sample the WebViewer was added as follows:

<ActiveReportsWeb:WebViewer ID="WebViewer1" runat="server" Height="100%" Width="100%" ViewerType="AcrobatReader" />

这是足以让WebViewer中的视图中工作。

That is enough to get the WebViewer working on the view.

在控制器中,我们指定了一个ActiveReport如下:

In the controller we specified an ActiveReport as follows:

ViewData["Report"] = new SampleReport();

在View的codebehind我们勾到视图报告:

In the codebehind of the View we hook the report to the view:

WebViewer1.Report = ViewData["Report"] as ActiveReport3;

那么棘手的部分开始。有ASP.NET下运行一些观众类型如的AcrobatReader / PDF时,使用的ActiveReports一些IHttpHandlers。为了确保我们的处理程序工作,你必须得到ASP.NET MVC路由,让他们来处理正常。幸运的是很容易做到这一点。只需code的下面一行添加到该文件的Global.asax.cs:

Then the tricky part begins. There are some IHttpHandlers used by ActiveReports when running under ASP.NET for some of the viewer types such as AcrobatReader / PDF. To ensure our handlers are working you must get ASP.NET MVC routing to allow them to process as normal. Luckily it is easy to do so. Just add the following line of code to the Global.asax.cs file:

routes.IgnoreRoute("{*allarcachitems}", new { allarcachitems = @".*\.ArCacheItem(/.*)?" });

这会忽略路线。需要注意的是,根据我的阅读可能有问题,因为ASP.NET路由似乎只允许一个单一的一网打尽像这样的路线。因此,如果你有这些IgnoreRoute的多个命令,或者你有一个个.axd文件中的任何问题,你需要修改的约束字典参数accomidate了个.axd以及.ArCacheItem。

That will ignore the route. Note that according to my reading there may be problems since ASP.NET routing seems to allow only a single "catch all" route like this. Therefore, if you have multiple of these IgnoreRoute commands and or you have any problems with a .axd file, you'll need to modify the constraints dictionary argument to accomidate the .axd as well as .ArCacheItem.

有关详细信息,请参阅以下文章:<一href=\"http://haacked.com/archive/2008/07/14/make-routing-ignore-requests-for-a-file-extension.aspx\">http://haacked.com/archive/2008/07/14/make-routing-ignore-requests-for-a-file-extension.aspx

For more information see the following article: http://haacked.com/archive/2008/07/14/make-routing-ignore-requests-for-a-file-extension.aspx

您可以在<一个从我们的论坛下载全样本href=\"http://www.datadynamics.com/forums/ShowPost.aspx?PostID=121907#121907\">http://www.datadynamics.com/forums/ShowPost.aspx?PostID=121907#121907

斯科特Willeke

数据动态/ GrapeCity的

Scott Willeke
Data Dynamics / GrapeCity

这篇关于如何使活动报告Web查看在ASP.NET MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆