【发布时间】:2017-09-05 23:49:25
【问题描述】:
我正在尝试获取数组列表中带有索引的每个项目的值,我使用此代码完成了此操作,但循环完成后没有显示值。
foreach (var item in (List<string[]>)TempData["verification_errors"])
{
<p>@item[0].ToString() + @item[2].ToString()</p>
}
这是List<string[]>
List<string[]> Data_verification_errors = new List<string[]>();
string[] Cust_Surname = new string[] { "CustomerSurname", reservation_details.CustomerSurname, "Customer name must have at least 2 characters" };
Data_verification_errors.Add(Cust_Surname);
【问题讨论】:
-
什么是
TemData?如果它真的是ArrayList,则转换为List<string[]>应该失败,你会得到InvalidCastException。 -
你不需要在循环之前先将你的 TempData 反序列化为一个列表对象吗?
-
我想 OP 表示数组列表,
List<string[]>。然而,这不是ArrayList,所以你应该澄清你的问题。 -
@HimBromBeere 临时数据我将数组列表存储在其中,以发送视图
-
避免使用术语
ArrayList,因为这是(旧).NET 类的名称,因此会导致混淆。您可能的意思是数组列表。
标签: c# asp.net asp.net-mvc arraylist asp.net-core