C# MVC部分控制:“;找不到IViewDataContainer对象。ViewUserControl必须位于ViewPage、ViewMasterPage中;
我正在尝试在MVC中实现SSRS查看器。在经历了很多痛苦和折磨之后,我通过一个自定义控件基本上实现了这个功能 报告呈现良好,但我尝试将模型传递给控件,如下所示:C# MVC部分控制:“;找不到IViewDataContainer对象。ViewUserControl必须位于ViewPage、ViewMasterPage中;,c#,asp.net-mvc,asp.net-mvc-4,reporting-services,asp.net-mvc-partialview,C#,Asp.net Mvc,Asp.net Mvc 4,Reporting Services,Asp.net Mvc Partialview,我正在尝试在MVC中实现SSRS查看器。在经历了很多痛苦和折磨之后,我通过一个自定义控件基本上实现了这个功能 报告呈现良好,但我尝试将模型传递给控件,如下所示: @Html.Partial("VendorReport", Model) 要调用此ascx控件,请执行以下操作: <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="VendorReport.ascx.cs" Inherits="ExtendedService
@Html.Partial("VendorReport", Model)
要调用此ascx控件,请执行以下操作:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="VendorReport.ascx.cs" Inherits="ExtendedServicesReportingPortal.Views.Reports.VendorReport" %>
以下是相关的控制器方法:
public ActionResult TransactionCountsAndInvoiceAmounts(TransactionCountsAndInvoiceAmountsModel model)
{
if(model == null) model = new TransactionCountsAndInvoiceAmountsModel();
return View(model);
}
MVC非常新,我遗漏了什么?我认为这里的问题是,在使用用户控件的地方,
ViewPage.Model
属性将为空,因为该控件无权访问/使用ViewData。您可能需要将模型传递到用户控件中
这里有一些例子,也展示了在MVC视图中重用Web表单用户控件,包括传递模型
The ViewUserControl '~/Views/Reports/RazorReportViewer.ascx' cannot find an IViewDataContainer object. The ViewUserControl must be inside a ViewPage, a ViewMasterPage
public ActionResult TransactionCountsAndInvoiceAmounts(TransactionCountsAndInvoiceAmountsModel model)
{
if(model == null) model = new TransactionCountsAndInvoiceAmountsModel();
return View(model);
}