C#遍历动态对象属性

原创
2015/12/04 17:51
阅读数 1.5K

C#遍历动态对象属性,在模版中Mdel.yuyue是个动态对象dynamic

<table class="table table-bordered table-hover" id="mytable">
    <thead>
        <tr>
            <th>key</th>
            <th>value</th>
        </tr>
    </thead>
    <tbody>
        @foreach(var pinfo in Model.yuyue.GetType().GetProperties()){
            <tr><td>@pinfo.Name</td><td>@pinfo.GetValue(Model.yuyue,null)</td></tr>
        }
    </tbody>
</table>



展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
0 评论
0 收藏
0
分享
返回顶部
顶部