我的数组列表有问题,无法在视图中读出
这里我有代码
DB:这里我从数据库中读出数据
ArrayList result = new ArrayList();
MySqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
ArrayList temp = new ArrayList();
temp.Add(reader["Voornaam"].ToString());
temp.Add(reader["Tussenvoegsel"].ToString());
temp.Add(reader["Achternaam"].ToString());
temp.Add(reader["Adres"].ToString());
temp.Add(reader["Postcode"].ToString());
temp.Add(reader["Plaats"].ToString());
temp.Add(reader["Land"].ToString());
temp.Add(reader["Geboortedatum"].ToString());
temp.Add(reader["Telefoonnummer"].ToString());
temp.Add(reader["Mobielnummer"].ToString());
temp.Add(reader["Email"].ToString());
result.Add(temp);
}
reader.Close();
}
else
{
}
return result;
控制器:制作arraylist gebruikers并将其发送到视图
DB dbase = new DB();
ArrayList Gebruikers = dbase.getGebruikerALL(Session["Bid"].ToString());
return View(Gebruikers);
查看:在foreach中读出数组
@model IEnumerable<EventRentalSystem.Models.ProfielModels>
@foreach (var item in Model)
{
<tr>
<td>@Html.DisplayFor(modelItem => item.Gebruikersnaam)</td>
<td>@Html.DisplayFor(modelItem => item.Voornaam)</td>
<td>@Html.DisplayFor(modelItem => item.Tussenvoegsel)</td>
<td>@Html.DisplayFor(modelItem => item.Achternaam)</td>
<td>@Html.DisplayFor(modelItem => item.Adres)</td>
<td>@Html.DisplayFor(modelItem => item.Postcode)</td>
<td>@Html.DisplayFor(modelItem => item.Plaats)</td>
<td>@Html.DisplayFor(modelItem => item.Land)</td>
<td>@Html.DisplayFor(modelItem => item.Geboortedatum)</td>
<td>@Html.DisplayFor(modelItem => item.Telefoonnummer)</td>
<td>@Html.DisplayFor(modelItem => item.Mobielnummer)</td>
<td>@Html.DisplayFor(modelItem => item.Email)</td>
<td><a class="edit" href="javascript:;">Bewerk</a></td>
<td><a class="delete" href="javascript:;">Verwijder</a></td>
</tr>
}
仍然得到错误:
传递到字典中的模型项的类型为“System.Collections.ArrayList”,但此字典需要类型为“System.Collections.Generic.IEnumerable`1[EventRentalSystem.Models.ProfielModels]”的模型项。
有人知道我如何读出视图中的数组吗?