如何从视图访问字典模型属性值-ASP.Net MVC

问题描述 投票:-1回答:1

我想从View中获取Dictionary的价值。在视图中,我有一个主/第一个[[foreach循环从Model检索数据,并且在main / first循环内,我需要根据第一个循环检索ListAttribute值通过ID。

**//Code in the View - First loop to retrieve data from Model** foreach (var item in Model.OrderBy(x => x.Id)) { <div class="col-xs-18 col-sm-4"> <div class="thumbnail"> *...(remainer of the code)* //Here to insert second loop to retrieve *ListAttribute* } //Code in the Model namespace ABC.Web.Models.Room { public class Housing { public string[] FloorPlan { get; set; } public Dictionary<string, ListAttribute> ListAttributes { get; set;} public string Latitude { get; set; } } public partial class ListAttribute { public string name { get; set; } public string icon { get; set; } public string value { get; set; } } }
c# .net asp.net-mvc
1个回答
0
投票
如果itemHousing类型的对象,则可以执行此操作:

foreach (KeyValuePair<string, ListAttribute> listItem in item.ListAttributes) { // Then you will have... // listItem.Key -> string // listItem.Value -> ListAttribute }

Source
© www.soinside.com 2019 - 2024. All rights reserved.