C# 如何在ASP.NET MVC 5 Razor模板引擎中将字典绑定到局部视图

C# 如何在ASP.NET MVC 5 Razor模板引擎中将字典绑定到局部视图,c#,asp.net,asp.net-mvc,razor,asp.net-mvc-5,C#,Asp.net,Asp.net Mvc,Razor,Asp.net Mvc 5,我有下面的演讲课 public class CustomerReportPresentation { public ReportFormat ReportFormat { get; set; } public List<Dictionary<string, object>> Data { get; set; } } 我正在将列表传递给局部视图。然后,每个局部视图将以不同的方式显示数据 这是我的部分观点 @model List<Dictionary

我有下面的演讲课

public class CustomerReportPresentation
{
    public ReportFormat ReportFormat { get; set; }

    public List<Dictionary<string, object>> Data { get; set; }
}
我正在将列表传递给局部视图。然后,每个局部视图将以不同的方式显示数据

这是我的部分观点

@model List<Dictionary<string, Object>>

<ul>
    @foreach (var attributes in Model.Data)
    {
        <li>
            @foreach (var attribute in attributes)
            {
                @attribute.Value; <text>   </text>

            }
        </li>
    }
</ul>

如何解决此问题?

您将
Model.Data
发送到分部中,然后尝试访问分部中的
Model.Data
。从上一个
型号中删除
数据
。奇怪的是,intellisense没有警告您,
Model.Data
列表中不存在


虽然你是对的,但这个问题仍然存在。这可能是因为我将视图放在自定义文件夹中。
@model Project1.Areas.Test.Presentation.CustomerReportPresentation
@{
    ViewBag.Title = "Index";
}

@if (Model.ReportFormat == Project1.Support.ReportsGenerator.Report.Contracts.ReportFormat.Summary)
{
    @Html.Partial("~/Support/ReportsGenerator/Views/Summary.cshtml", Model.Data)
}
else
{
    @Html.Partial("~/Support/ReportsGenerator/Views/Tabular.cshtml", Model.Data)
}
@model List<Dictionary<string, Object>>

<ul>
    @foreach (var attributes in Model.Data)
    {
        <li>
            @foreach (var attribute in attributes)
            {
                @attribute.Value; <text>   </text>

            }
        </li>
    }
</ul>
 Compiler Error Message: CS0103: The name 'model' does not exist in the current context
@model List<Dictionary<string, Object>>

<ul>
@foreach (var attributes in Model)
{
    <li>
        @foreach (var attribute in attributes)
        {
            @attribute.Value; <text>   </text>

        }
    </li>
}
</ul>
// At the end you sendt Model.Data, that means the Data object is recieved by the Partial
@Html.Partial("~/Support/ReportsGenerator/Views/Summary.cshtml", Model.Data)