我有这样一类具有一个泛型类型:Html.DisplayFor与泛型类
Document<T>
这个类是一个视图模型的一部分
public class MyViewModel
{
public IEnumerable<Document<T>> Documents {get;set;}
}
我想使用DisplayFor将发送到view.cshtml中的相应模板
@model MyViewModel
foreach(var vm in Model.Documents)
{
@Html.DisplayFor(vm)
}
但是我d on't知道如何创建具有类的名称共享/ DisplayTemplates模板,但C#的名称不需要使用泛型参数:
Document`1
但这是insufficent,因为它不识别完整的类型结构体。
有没有办法将DisplayFor与DisplayTemplates和Generic Types一起使用?
这可能有助于http://stackoverflow.com/questions/10616042/mvc3-razor-editor- display-templates-and-generics –
[ASP.NET MVC 3 Generic DisplayTemplates](http://stackoverflow.com/questions/5286706/asp-net-mvc-3-generic-displaytemplates) –
@Kyle - That问题是提出相关的问题,但稍有不同 - 我可以为所有类型的泛型使用一个模板。我正在尝试为每种类型获取一个模板。 – Doug