私はこのようなものを持っています
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>
では、どうすればこれを機能させることができますか?