【发布时间】:2011-04-03 19:17:22
【问题描述】:
我有这样的事情
public class ViewModel1
{
// some properties here
public List<ViewModel2> ViewModel2 {get; set;}
}
public class ViewModel2
{
public string A {get; set;}
public string B {get; set;}
}
// view
<table>
<thead>
<tr> a </tr>
<tr> b </tr>
</thead>
<tbody>
// want to use a display template to render table row and cells so I don't need to use for loop
</tbody>
</table>
我尝试使用“@Html.DisplayForModel()”,但我似乎采用了视图的 viewModel(所以在我的情况下为 ViewModel1)
我需要使用 ViewModel2,但我没有看到任何传入 ViewModel2(模型对象)的选项。
然后我尝试了
@Html.DisplayFor(x => x.ViewModel2)
这并不好,它只是像第一个属性值一样打印出来,甚至从未生成任何单元格。
这里基本上是我的展示模板
@model ViewModel2
<tr>
<td>@Model.A</td>
<td>@Model.B</td>
</tr>
那么我怎样才能做到这一点呢?
【问题讨论】:
标签: c# asp.net-mvc asp.net-mvc-3 display-templates