案例1: 基本上,你可以在你的应用程序本身中观察到这一点。 MVC本身为您提供答案。什么时候 ?在针对返回列表的操作创建View时。说你的行动返回客户名单,然后你可以观察以下代码。
@model IEnumerable<Customer>
<h2>Customers</h2>
<p>
@Html.ActionLink("Create New", "CreateCustomer", "ControllerName")
</p>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.Email)
</th>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Email)
</td>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.ActionLink("Edit |", "UpdateCustomer", new { id = item.Id})
@Html.ActionLink("Details", "Details", new { id = item.Id})
@Html.ActionLink("Delete", "Delete", new { id = item.Id})
</td>
</tr>
}
</table>
案例2: 当你发送内ViewData的列表中选择您的情况是。然后你必须将ViewData转换为相应的模型列表,然后你可以执行相同的foreach循环。 操作: var info = add.jumbo(); ViewData [“sample”] = info;
return View("FormResults");
查看:
@if (ViewData["sample"] != null)
{
List<Info> infoList = (List<Info>)ViewData["sample"];
foreach (var i in infoList)
{
//Perform your html here enclosed with html tags.
}
}
太棒了。感谢您的发布。它工作正常。 – Vib 2014-12-10 06:49:36