0

我将这种类型传递到我的视图中

Dictionary<String, List<myObj>> results = ...

View(results);

我的观点有这个声明

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<Models.myObj>>" %>

我遇到了这个错误:

`The model item passed into the dictionary is of type 'System.Collections.Generic.Dictionary`2[System.String,System.Collections.Generic.List`1[Models.myObj]]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[Models.myObj]'.`

这是因为我发送到视图的新结构。如何自动更新视图以使其使用新的参数类型?

我没有使用 Razor 视图

视图将显示手风琴,其中键是手风琴的名称,字典的值将是手风琴选项卡展开时显示的数据

4

1 回答 1

1

更改视图中的类型:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IDictionary<string, List<Models.myObj>>>" %>

我对 ASPX 视图引擎有点生疏,但你应该能够像这样循环:

<% foreach(var item in Model) { %>

   //some html

<% } %>
于 2013-09-17T19:41:58.167 回答