我有这样的事情
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()
”,但我似乎采取的视图的视图模型(所以在我的情况ViewModel1)
我需要使它采取ViewModel2,但我没有看到任何选项ViewModel2传递(模型对象)。
然后,我尝试
@Html.DisplayFor(x => x.ViewModel2)
没有工作,很好地它只是打印出像第一属性值,甚至从来没有所做的任何细胞。
这基本上是我显示模板
@model ViewModel2
<tr>
<td>@Model.A</td>
<td>@Model.B</td>
</tr>
那么,如何使这项工作?