我喜欢MvcContrib Grid的AutoGenerateColumns功能,但它似乎只适用于简单的对象。是否有可能让它遍历复杂对象的属性?或者是否需要使用column.For()
手动执行此操作?
一个例子是一个User对象,它将Address对象作为其属性之一。
答案 0 :(得分:3)
不。网格仅循环通过单层属性。 MVCContrib Grid不会递归深入到您的对象中。
如果你看the source:
foreach(var property in modelMetadata.Properties)
{
if(!property.ShowForDisplay)
{
continue;
}
var column = For(PropertyToExpression(property));
if(!string.IsNullOrEmpty(property.DisplayName))
{
column.Named(property.DisplayName);
}
if(!string.IsNullOrEmpty(property.DisplayFormatString))
{
column.Format(property.DisplayFormatString);
}
}