C# 以比mvc asp.net表更好的格式显示数据库中的记录列表
我正在寻找一种更好的方法,以在视图中显示数据库中的记录列表,而不是使用普通表和“for each”循环,如下所示:C# 以比mvc asp.net表更好的格式显示数据库中的记录列表,c#,html,asp.net,model-view-controller,asp.net-mvc-5,C#,Html,Asp.net,Model View Controller,Asp.net Mvc 5,我正在寻找一种更好的方法,以在视图中显示数据库中的记录列表,而不是使用普通表和“for each”循环,如下所示: <table class="table"> <tr> <th> @Html.DisplayNameFor(model => model.date) </th> <th> @Html.DisplayNameFor(model => model.name)
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.date)
</th>
<th>
@Html.DisplayNameFor(model => model.name)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.date)
</td>
<td>
@Html.DisplayFor(modelItem => item.name)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.id }) |
@Html.ActionLink("Details", "Details", new { id=item.id }) |
@Html.ActionLink("Delete", "Delete", new { id=item.id })
</td>
</tr>
}
</table>
@DisplayNameFor(model=>model.date)
@DisplayNameFor(model=>model.name)
@foreach(模型中的var项目){
@DisplayFor(modelItem=>item.date)
@DisplayFor(modelItem=>item.name)
@ActionLink(“编辑”,“编辑”,新的{id=item.id})|
@ActionLink(“详细信息”,“详细信息”,新的{id=item.id})|
@ActionLink(“删除”,“删除”,新的{id=item.id})
}
我最好以“概要文件”类型的格式显示每条记录,如下所示:
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.date)
</th>
<th>
@Html.DisplayNameFor(model => model.name)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.date)
</td>
<td>
@Html.DisplayFor(modelItem => item.name)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.id }) |
@Html.ActionLink("Details", "Details", new { id=item.id }) |
@Html.ActionLink("Delete", "Delete", new { id=item.id })
</td>
</tr>
}
</table>
用模型中的属性替换虚拟文本
body{padding top:30px;}
.glyphicon{页边距底部:10px;页边距右侧:10px;}
小的{
显示:块;
线高:1.428571429;
颜色:#999;
}
@foreach(模型中的var项目){
巴米克·帕特尔
美国旧金山
email@example.com
1988年6月2日
}
当然可以。我建议使用dl
列表而不是表格。关于该列表的更多信息:这是一个HTML问题。如果你在谷歌上搜索,你会发现很多教程、控件工具、Javascript库,它们使用div、CSS类和Javascript来实现。表格行不必包含单元格,@foreach
也不必创建表格。检查样式例如,它允许您仅使用div创建一张卡。您的@foreach
可以创建这样的节,而不是表行感谢您!不客气,如果您满意,请标记为正确答案。