c# mvc 多个@model 如何定义

聪明的傻瓜 2012-09-19 06:18:34
@model ICollection<Products>

@model Products

如果我页面使用对象较多,model 重复了怎么办

有循环的列表,也有单纯的对象展示
@foreach (Products product in Model)
{
}
@Html.Raw(Model.Content)

Model对象冲突了。如果都是列表,那么数据一样了,如果是不一样的,报下面的异常

The model item passed into the dictionary is of type 'Products', but this dictionary requires a model item of type 'System.Collections.Generic.ICollection`1[Products]'.

请问多@model 对象如何定义,谢谢
...全文
538 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
xierimin 2014-05-05
  • 打赏
  • 举报
回复
建个类 : using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace WebMvc.ViewData { public class ModelViewData : ViewDataBase { public IEnumerable<Maticsoft.Model.Product> Products { get; set; } public IEnumerable<Maticsoft.Model.News> News { get; set; } } } 然后引用它

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧