Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVC部分控制:“;找不到IViewDataContainer对象。ViewUserControl必须位于ViewPage、ViewMasterPage中;_C#_Asp.net Mvc_Asp.net Mvc 4_Reporting Services_Asp.net Mvc Partialview - Fatal编程技术网

C# MVC部分控制:“;找不到IViewDataContainer对象。ViewUserControl必须位于ViewPage、ViewMasterPage中;

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

我正在尝试在MVC中实现SSRS查看器。在经历了很多痛苦和折磨之后,我通过一个自定义控件基本上实现了这个功能

报告呈现良好,但我尝试将模型传递给控件,如下所示:

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