如何在mvc视图中循环访问对象列表 [英] how to loop through list of object in mvc view

查看:54
本文介绍了如何在mvc视图中循环访问对象列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,

我想创建只有查看部分,我在哪里制作虚拟数据如下



Hi friends,
I want to create only view part, where in I'm making dummy data as below

@foreach (var item in new List<Object> {
                                           new { market = "UK", collectionGroupName="Collection Group 1",GTS="yes",processingCenter = "Processing Centre 1"},
                                           new { market = "UK", collectionGroupName="Collection Group 1",GTS="yes",processingCenter = "Processing Centre 1"},
                                           new { market = "UK", collectionGroupName="Collection Group 1",GTS="yes",processingCenter = "Processing Centre 1"},
                                           new { market = "UK", collectionGroupName="Collection Group 1",GTS="yes",processingCenter = "Processing Centre 1"},
                                       })
                                   {
                                       <tr>
                                           <td class="ProductListTable_TD">@item.market</td>
                                           <td class="ProductListTable_TD"></td>
                                           <td class="ProductListTable_TD"></td>
                                           <td class="ProductListTable_TD"></td>
                                           <td class="PadRig_AlignRgt">
                                               <input type="button" class="btnEdit" name="btnEdit" value="Edit" data-href="#content1" />
                                           </td>
                                       </tr>
                                   }





如何从物品进入市场,GTS和其他财产?



如果我尝试访问如下,则会出错。



How can I access the market, GTS and other property from the item?

If I try to access as below it gives an error

@item.market



有什么想法吗?



提前致谢


Any idea?

Thanks in advance

推荐答案

亲爱的,这是不可能的。 @item只是类型字符串而不是对象。你需要传递一个你需要使用Json.stringify的脚本。

你不能像这样访问@ item.market。

如果属性的值是静态的为什么要使用foreach和List<> ??

如果从模型即服务器端获取值,则使用foreach。

希望你得到。

请回复有关查询的评论。

谢谢

:)
This is not possible dear. Here the @item is just simply of type string not an object. You need to pass a script where you need to use Json.stringify.
You cannot access the @item.market like this.
If the values of the properties are static why use foreach and List<>??
If you get the values from Model i.e. Server side then use foreach.
Hope you get.
Please post back comments regarding queries if any.
Thanks
:)


这篇关于如何在mvc视图中循环访问对象列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆