【发布时间】:2015-12-13 00:23:17
【问题描述】:
我有一个 PaymentPlans 列表,并从中计算出每月的价格 List<Dictionary<string, long>>。
字符串 = 活动代码
long = 每月价格
我不知道如何在我的视图中显示当前 PaymentPlan 的价格。
@Model.PaymentPlans.PricePerMonth.FirstOrDefault(x => x.)
这是我脑子里一片空白的地方。
public class PaymentPlansIncPPM
{
public List<PaymentPlan> PaymentPlans { get; set; }
public List<Dictionary<string, long>> PricePerMonth { get; set; }
}
@foreach (var plan in Model.PaymentPlans)
{
<div>
@Html.RadioButton("CampaignId", plan.CampaignCode, new { @id = plan.CampaignCode })
<label for="@plan.CampaignCode"></label>
<span>
<b>@plan.ContractLengthInMonths months</b><br />
<-- Here is where I want to show the price per month -->
$/month
</span>
</div>
}
编辑: 字典包含一个或多个,总是匹配计划的数量。 (如果有帮助的话)
Key "campaignCode" string
Value 100000 long
Key "pricePerMonth" string
Value 42 long
【问题讨论】:
-
@NedStoyanov 据我了解 -
x是Dictionary,所以它没有Key属性 -
不要将
long用于财务/金钱价值,使用decimal。 -
字典列表中有什么?你想要这个吗? var correctDict = Model.PricePerMonth.First(pm => pm.Kesy.Any(k => k == plan.CampaignCode)); var pricePerMonth = correctDict[plan.CampaignCode];
-
@ArghyaC 更新了字典信息
-
这行得通吗? var correctDict = Model.PricePerMonth.First(dict => dict["campaignCode"] == plan.CampaignCode); var pricePerMonth = correctDict["pricePerMonth"];
标签: c# asp.net-mvc list dictionary