相关疑难解决方法(0)

强类型局部视图的问题

我有部分视图的问题.我正在asp.net mvc开发一个博客,我会在我的主页上列出一个类别列表,最后发表的帖子,最后的评论.我认为最好的解决方案是使用强类型的局部视图,并在每个局部视图中传递必要的模型.

我的问题是View ..在任何视图(连接到母版页的contentplaceholder)中的模型与部分视图中的模型冲突,我得到如下错误:

The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[Blog.Models.Articoli]' but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[Blog.Models.Categorie]'. 
Run Code Online (Sandbox Code Playgroud)

我在网上发现了一个肮脏的解决方案,它包括传递任何视图的模型,一些viewdata,每个模型都可以在局部视图中传递.但是这个解决方案不尊重DRY原则.因为你必须为每个动作重复这个代码!

所以,我的问题是:我可以创建一个包含局部视图模型的模型吗?如果,是的,以这种方式?

它存在另一种解决方案更简单吗?

感谢帮助

asp.net-mvc

0
推荐指数
1
解决办法
2445
查看次数

标签 统计

asp.net-mvc ×1