在mvc4中创建通用的mvc视图 [英] create generic mvc view in mvc4
本文介绍了在mvc4中创建通用的mvc视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我之前也提出过类似的问题,没有答案.
I have raised similar question before, have got no answers.
如何创建通用的mvc4视图,该视图可以显示传递给它的列表或单个模型.模型可以是人",组织"或派对",无论传递给它的是什么.
How can I create a generic mvc4 view that can display list of or a single model that is passed to it. model can be either Person or Organization or Party whatever that is passed to it.
推荐答案
如果您正在寻找类似的东西:
If you are looking for something like:
@model MyViewModel<T> where T : IViewModel
...那么Razor不支持.
... then that is not supported by Razor.
您也许可以使用类似这样的东西:
You may be able to use something like this:
@model MyViewModel<IViewModel>
...这样,您可以定义可以按以下方式传递的所有类型
... that way you could define all types that could be passed as follows
public class Person : IViewModel { ... }
public class Organisation : IViewModel { ... }
public class Party : IViewModel { ... }
这篇关于在mvc4中创建通用的mvc视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文