【发布时间】:2015-05-17 00:48:02
【问题描述】:
string[] showProperties = {"id", "name"};
@*
user has many properties, id, name, address, etc...
*@
<!-- now I just want to show the properties in the shownProperties list -->
@for (int j = 0; j < showProperties.Length; j++)
{
<td>
@user.showProperties[j]
</td>
}
通常我会使用@user.id 或@user.name 来显示,但在这种情况下,[property] 是由 showColumns 数组的值动态拉取的。
上面的 @user.showProperties[j] 不起作用,例如 Razor 不会将 id 识别为属性。有没有办法将'id'注入@user.[]作为@user.id?
如何正确使用@user.(mydynamicproperty)?
【问题讨论】:
标签: c# asp.net-mvc razor