我想填充一个 IEnumerable 来构建一个循环,以按数组长度贯穿我。该值将被添加到函数中发生 2 次的结果列表中,即 Seaons 和 Categories。每个数组的长度为两个值。如果我现在花在 .cshtml 中,当两个值之一较高时,我会得到两次
// Set List
List<Template> result = new List<Template>();
List<TemplateList> tmp_list = new List<TemplateList>();
// Categories
string[] Categories_Array = TemplateModel.GetRoomCategories.Split(',');
// SeasonData
string[] SeasonData_Array = TemplateModel.GetSeasonsData.Split(',');
for (int i = 0; i < Categories_Array.Length; i++)
{
string[] Categories = Categories_Array[i].Split(';');
tmp_list.Add(new TemplateList { CategoreList = Categories[0], PriceList = "125,00" });
for (int a = 0; a < SeasonData_Array.Length; a++)
{
string[] SeasonData = SeasonData_Array[a].Split(';');
result.Add(new Template { GetSeasonsData = SeasonData[0] });
}
}
result.Add(new Template { TemplateLists = tmp_list });
return result.AsEnumerable();
cshtml
<table class="table" cellpadding="0" cellspacing="0" border="0">
<tr>
<th class="header">Season</th>
@foreach (var item in Model)
{
<th class="header">@item.GetSeasonsData</th>
}
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0" border="0">
@foreach (var item in Model)
{
foreach (var extra in item.TemplateLists)
{
<tr class="double">
<td class="roomlist">@extra.CategoreList</td>
<td class="pricelist">@extra.PriceList</td>
</tr>
}
}
</table>
</td>
</tr>
阵列:类别EZ;1,DZ;2
季节Summer;01.12.2013;31.12.2013,Winter;01.06.2013;31.06.2013
仅当有 3 个类别时,只有 1 个季节仍然可用 3 个“tr”,没有按季节加载
谢谢你