MVC Partial Control:“找不到IViewDataContainer对象.ViewUserControl必须在ViewPage内,ViewMasterPage”

时间:2014-03-27 17:48:36

标签: 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="ExtendedServicesReportingPortal.Views.Reports.VendorReport" %>
<uc1:RazorReportViewer ID="VendorReportViewer" runat="server" ...Omitted Custom Properties...  />

但是如果我尝试访问模型,我会收到此错误:

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);
    }

MVC很新,我错过了什么?

1 个答案:

答案 0 :(得分:1)

我认为这里的问题是,在使用用户控件的地方,ViewPage.Model属性将为null,因为控件无法访问/使用ViewData。您可能需要将模型传递给用户控件。

有一些示例herehere显示了在MVC视图中重用Web窗体用户控件,包括传入模型。

相关问题