【发布时间】:2011-09-01 03:37:05
【问题描述】:
尝试将我的对象传递给视图时出现此错误。我是 MVC 的新手,所以请原谅我。
传入字典的模型项的类型为 'System.Collections.Generic.List1[<>f__AnonymousType13[System.Int32,System.String,System.Nullable1[System.DateTime]]]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[MvcApplication1.Models.storageProperty]'
我正在尝试传递一个表的列表,该表将显示 storageProperty 表中的对象以及费用表中的最后日期(如果有的话)。大多数物业至少进行过一次费用审计,有些进行了多次审计,而另一些则没有。 这是控制器的代码:
var viewModel = db.storageProperties.Select(s => new
{
s.storagePropertyId,
s.BuildName,
latestExpenseSurvey = (DateTime?)s.expenses.Max(e => e.expenseDate)
}).ToList();
return View(viewModel);
}
并且视图中的@model 语句需要一个 storageproperty 对象。我正在将 mvc3 与实体框架一起使用。很明显,我不能传递这个列表对象来代替 storageproperty 对象,但我不知道该怎么做,我应该怎么做?
提前致谢。
【问题讨论】:
标签: c# asp.net-mvc-3