我遇到了一件小事,我正在使用MVC5并尝试从数据库访问表并在View上显示它。 只有一列的表我这样做但不是一种有效的方法,所以需要你的帮助
@{
int c = Model.Count();
}
@foreach (var item in Model)
{
if (c >= 16)
{
<td>@Html.ActionLink( item.Name,"Jobs" ,new{name = item.Name})</td>
}
else if (c== 15)
{
<tr></tr>
<td>@Html.ActionLink( item.Name,"Jobs" ,new{name = item.Name})</td>
}
else if (c>=11)
{
<td>@Html.ActionLink( item.Name,"Jobs" ,new{name = item.Name})</td>
}
else if (c==10)
{
<tr></tr>
<td>@Html.ActionLink( item.Name,"Jobs" ,new{name = item.Name})</td>
}
else if (c>=6)
{
<td>@Html.ActionLink( item.Name,"Jobs" ,new{name = item.Name})</td>
}
else if (c==5)
{
<tr></tr>
<td>@Html.ActionLink( item.Name,"Jobs" ,new{name = item.Name})</td>
}
else if (c>=0)
{
<td>@Html.ActionLink( item.Name,"Jobs" ,new{name = item.Name})</td>
}
c --;
}
</tr></Table>
连续5个colomns,然后创建包含五列的新行。
答案 0 :(得分:0)
假设您的模型还有其他属性,例如Column2
,Column3
等,那么这将为您提供5列:
<table class="table" >
<tr>
@foreach (var item in Model)
{
<td>@Html.ActionLink(item.Category, "Jobs")</td>
<td>@Model.Column2</td>
<td>@Model.Column3</td>
<td>@Model.Column4</td>
<td>@Model.Column5</td>
}
</tr>
</table>