Asp.net mvc 3 如何在asp.net mvc3中从列表中打印两列图片
我有这段代码,我有点怀疑如何让它打印2行而不是1行(稍后,如果可能的话,我希望它是动态的,取决于屏幕大小,但现在它应该只有2列)Asp.net mvc 3 如何在asp.net mvc3中从列表中打印两列图片,asp.net-mvc-3,html,Asp.net Mvc 3,Html,我有这段代码,我有点怀疑如何让它打印2行而不是1行(稍后,如果可能的话,我希望它是动态的,取决于屏幕大小,但现在它应该只有2列) @model IEnumerable @{ ViewBag.Title=“Index”; } 指数 @ActionLink(“新建”、“创建”) 标题 路径 音乐会年 标题 路径 音乐会年 @布尔偶数=假; @foreach(模型中的var项目){ @DisplayFor(modeleItem=>item.Title) @DisplayFor(modelItem
@model IEnumerable
@{
ViewBag.Title=“Index”;
}
指数
@ActionLink(“新建”、“创建”)
标题
路径
音乐会年
标题
路径
音乐会年
@布尔偶数=假;
@foreach(模型中的var项目){
@DisplayFor(modeleItem=>item.Title)
@DisplayFor(modelItem=>item.ConcertYear)
}
因此,我希望布尔值成为左列和右列之间的开关我不知道如何使用左列或右列的布尔值标志,但是如果您只是在两列之后,您可以这样做(为拼写错误/语法错误道歉,但您明白了)
@for(int i=0;iModel[i].Title)
@DisplayFor(modelItem=>Model[i]
@如果(Model.ContactMethods.Count>i+1)
{
@DisplayFor(modelItem=>Model[i+1].Title)
@DisplayFor(modelItem=>Model[i+1].ConcertYear)
}
其他的
{
}
}
至于动态列,您需要查看jquery
@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>
@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>
}