我有这个代码,我有点怀疑如何让它打印2行而不是1行(后来我希望它是动态的,具体取决于screenize,如果可能,但现在它应该只是2列)< / p>
@model IEnumerable<FirstWeb.Models.Picture>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
Title
</th>
<th>
Path
</th>
<th>
ConcertYear
</th>
<th>
Title
</th>
<th>
Path
</th>
<th>
ConcertYear
</th>
</tr>
@bool even = false;
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Title)
</td>
<td>
<a href=@Html.DisplayFor(modelItem => item.Path)><img src=@Html.DisplayFor(modelItem => item.Path) width="250px" /> </a>
</td>
<td>
@Html.DisplayFor(modelItem => item.ConcertYear)
</td>
</tr>
}
</table>
所以我希望布尔值是左右列之间的切换
答案 0 :(得分:0)
我不知道你怎么能用左边或右边的布尔标志来做,但是如果你只是在两列之后,你可以做这样的事情(道歉/语法错误道歉,但你明白了)。
@for (int i = 0; i < Model.ContactMethods.Count; i += 2)
{
<tr>
<td>
@Html.DisplayFor(modelItem => Model[i].Title)
</td>
<td>
<a href=@Html.DisplayFor(modelItem => Model[i].Path)>
<img src=@Html.DisplayFor(modelItem => Model[i].Path) width="250px" />
</a>
</td>
<td>
@Html.DisplayFor(modelItem => Model[i].ConcertYear)
</td>
@if (Model.ContactMethods.Count > i + 1)
{
<td>
@Html.DisplayFor(modelItem => Model[i + 1].Title)
</td>
<td>
<a href=@Html.DisplayFor(modelItem => Model[i + 1].Path)>
<img src=@Html.DisplayFor(modelItem => Model[i + 1].Path) width="250px" />
</a>
</td>
<td>
@Html.DisplayFor(modelItem => Model[i + 1].ConcertYear)
</td>
}
else
{
<td colspan="3"></td>
}
</tr>
}
就动态列而言,您需要查看jquery