通过ASPX创建RDLC报告,视图必须从ViewPage错误派生
本文关键字:ViewPage 错误 派生 视图 创建 ASPX RDLC 报告 通过 | 更新日期: 2023-09-27 18:16:36
我有一个使用VS2013的MVC5项目,并试图遵循这里的12个步骤来创建一个rdlc报告。http://www.dotnetawesome.com/2015/01/how-to-display-rdlc-report-in-report-viewer-control-into-mvc4.html
然而,我在局部视图渲染时一直得到这个错误。
The view must derive from ViewPage, ViewPage<TModel>, ViewUserControl, or ViewUserControl<TModel>.
我查找了所有类似的文章,尝试在web中添加System.Web.Mvc.ViewPage的参考。View下的配置,通过继承。还尝试在Global.asax/RouteConfig.cs中添加IgnoreRoute .
routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
然而,我仍然收到这个错误:(有什么建议吗?)
Server Error in '/' Application.
The view at '~/Views/Shared/RPT_Test_ASPX.aspx' must derive from ViewPage, ViewPage<TModel>, ViewUserControl, or ViewUserControl<TModel>.
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.InvalidOperationException: The view at '~/Views/Shared/RPT_Test_ASPX.aspx' must derive from ViewPage, ViewPage<TModel>, ViewUserControl, or ViewUserControl<TModel>.
Source Error:
Line 3: }
Line 4: <h2>My Test List</h2>
Line 5: @Html.Partial("RPT_Test_ASPX")
Line 6:
Line 7:
Source File: c:'SVN'TestProject'trunk'TestProject'Views'Report'Index.cshtml Line: 5
Stack Trace:
[InvalidOperationException: The view at '~/Views/Shared/RPT_Test_ASPX.aspx' must derive from ViewPage, ViewPage<TModel>, ViewUserControl, or ViewUserControl<TModel>.]
System.Web.Mvc.WebFormView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +278
System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +382
System.Web.Mvc.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, TextWriter writer, ViewEngineCollection viewEngineCollection) +467
System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData) +155
System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName) +91
ASP._Page_Views_Report_Index_cshtml.Execute() in c:'SVN'TestProject'trunk'TestProject'Views'Report'Index.cshtml:5
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +270
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +122
System.Web.WebPages.StartPage.RunPage() +63
System.Web.WebPages.StartPage.ExecutePageHierarchy() +100
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +131
System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +695
System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +382
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +431
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +39
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +116
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +529
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +106
System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +321
System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +185
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +34
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44
System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +39
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +62
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +39
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9644097
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1055.0
终于在这里找到了答案:https://reportviewerformvc.codeplex.com/wikipage?title=Getting%20Started
基本上,通过NuGet安装ReportViewerForMvc,
PM> Install-Package ReportViewerForMvc
,它会放一个ReportViewerWebForm。"Aspx"页位于项目的根目录。做好你的本职工作。数据源映射到你的控制器中,把它放在ViewBag中,然后调用View。
在View (cshtml)页面中添加
@using ReportViewerForMvc
,并在正文中添加此查看器。
@Html.ReportViewer(ViewBag.ReportViewer as Microsoft.Reporting.WebForms.ReportViewer)
这对我有用。希望这篇文章对大家有所帮助。
这是我的控制器代码:
MyEntities context = new MyEntities();
var myData = context.usp_MyStorProc(_var1, _var2);
ReportViewer reportViewer = new ReportViewer();
reportViewer.LocalReport.ReportPath = Request.MapPath(Request.ApplicationPath);
reportViewer.LocalReport.DataSources.Clear();
ReportDataSource rdc = new ReportDataSource("MyDataSourceName", myData);
reportViewer.LocalReport.DataSources.Add(rdc);
reportViewer.LocalReport.Refresh();
reportViewer.ProcessingMode = ProcessingMode.Local;
reportViewer.LocalReport.ReportPath += @"Reports/MyReportName.rdlc";
reportViewer.Width = 900;
reportViewer.Height = 600;
reportViewer.ZoomMode = ZoomMode.PageWidth;
ViewBag.MyReportName = reportViewer;
请确保包含所有的ReportViewer引用(可以在GAC中找到或从微软网站下载):
- Microsoft.ReportViewer.Common
- Microsoft.ReportViewer.ProcessingObjectModel
- Microsoft.ReportViewer.WebForms
- Microsoft.ReportViewer.WinForms