Scaffold Children Elements in RazorView

Oct 19, 2012 at 4:41 PM

I'm altering my Details.cs.t4 Scaffold Template to scaffold one table per children of my model, something following this template:

<#
foreach (ModelProperty property in GetModelProperties(Model.ViewDataType, true)) {
    if (property.IsForeignKey) {
#>
<p><!--#= The Child Model Name #--></p>
<table>
    <thead>
        <tr>
            <th></th>
            <th>Column</th>
            <th>Column</th>
        </tr>
    </thead>
    <tbody>
           <tr>
               <td><!--#= Actions #--></td>
               <td>Value</td>
               <td>Value</td>
           </tr>
    </tbody>
</table>

<#
    }
}
#>

The problem is: how can I retrieve data from children to iterate the properties from the model? 

First I tried to get the Model.ViewDataType.Children, but PowerShell returns an error informing the object is not serializable, then I tried to use Model.ViewDataType to get the maximum information I need, but it is still incomplete.

Ideas?