我怎么能遍历我的表在MVC的Razor视图显示由侧方的内容? [英] How can I loop through my table to display contents side by side in MVC Razor View?
问题描述
您好我想在并排放置的内容一边帮助。
现在,我可以在左侧和右侧分别显示的内容。但我需要从数据库中显示的记录。对于这个我使用foreach循环。所以,我怎么需要显示的是左侧和2月1日的记录上记录的右侧和第三左等。我怎么能遍历这个样子。
我stucked需要这儿过得帮助..
我用这code,但所有的内容都显示正如我前面说。
<身体GT;
@foreach(以型号VAR项) {
<! - 主表(您可以相应地定义填充) - GT;
<表格的宽度=80%BORDER =0CELLSPACING =0的cellpadding =5>
&所述; TR>
&所述; TD宽度=50%> <! - 表的左边 - >
<表格的宽度=100%BORDER =0CELLSPACING =0的cellpadding =1>
&所述; TR>
&所述; TD>
<跨度类=标题> APP< / SPAN>
< BR />
< DIV CLASS =listRowA的onmouseover =this.className ='listRowAHover'的onmouseout =this.className ='listRowA'>
< DIV CLASS =listPageCol的onclick =location.href ='.. /首页/ ControlPanel控制'>
<跨度类=listlCol1> < BR />
@ item.ID
< / SPAN>
<跨度类=listCol2>< IMG SRC =../内容/图片/ 20_thumb.jpgWIDTH =281HEIGHT =200BORDER =0ALT =图片/> < / SPAN>
< / DIV>
< / DIV> < / TD> < / TR> &所述; TR>
< TD>&安培; NBSP;< / TD>
< TD>< / TD>
< TD>&安培; NBSP;< / TD>
< / TR>
&所述; TR>
< TD>&安培; NBSP;< / TD>
&所述; TD> < / TD>
< TD>&安培; NBSP;< / TD>
< / TR>
< /表>
<! - 完 - >
< / TD>
&所述; TD宽度=50%> <! - 在表格右侧 - >
<表格的宽度=100%BORDER =0CELLSPACING =0的cellpadding =1>
&所述; TR> &所述; TD>
< DIV CLASS =listRowA的onmouseover =this.className ='listRowAHover'的onmouseout =this.className ='listRowA'>
<跨度类=listCol2>< IMG SRC =../内容/图片/ 20_thumb.jpgWIDTH =281HEIGHT =200BORDER =0ALT =图片/> < / SPAN>< / DIV>
< / TD>
< / TR>
&所述; TR>
< TD>&安培; NBSP;< / TD>
< TD>< / TD>
< TD>&安培; NBSP;< / TD>
< / TR>
&所述; TR>
< TD>&安培; NBSP;< / TD>
&所述; TD> < / TD>
< TD>&安培; NBSP;< / TD>
< / TR>
< /表>
<! - 完 - >
< / TD>
< /表><! - 主表完 - >
}
< /身体GT;
而不是
@foreach(以型号VAR项)
使用
@for(VAR I = 0; I< Model.Count;我+ = 2)
{}
和访问模型的属性,如
@Model [I] .ID
为了确定哪些应该去正确的应该向左走,你可以使用
@Model [I] .ID为左
和
@if(I + 1< Model.Count)
{
模型[I + 1] .ID右
}
只要确保 I + 1
是从来没有超过 Model.Count
Hi i want help in putting contents side by side.
Right now i can display content separately in left side and right side. But i need to display records from database. For this i am using foreach loop. So how i need to display is 1st records on left side and 2nd record on right side and 3rd on left and so on. How can i loop through like this.
I am stucked here.I need help..
I am using this code but all the contents are displaying as i told earlier.
<body>
@foreach (var item in Model)
{
<!-- Main Table(You can define padding accordingly) -->
<table width="80%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td width="50%">
<!-- Table on left side -->
<table width="100%" border="0" cellspacing="0" cellpadding="1">
<tr>
<td>
<span class="Title">APP</span>
<br/>
<div class="listRowA" onmouseover="this.className='listRowAHover'" onmouseout="this.className='listRowA'">
<div class="listPageCol" onclick="location.href='../Home/ControlPanel'">
<span class="listlCol1">
<br />
@item.ID
</span>
<span class="listCol2"><img src="../Content/Images/20_thumb.jpg" width="281" height="200" border="0" alt="image" /></span>
</div>
</div>
</td>
</tr>
<tr>
<td> </td>
<td></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<!-- END -->
</td>
<td width="50%">
<!-- Table on right side -->
<table width="100%" border="0" cellspacing="0" cellpadding="1">
<tr>
<td>
<div class="listRowA" onmouseover="this.className='listRowAHover'" onmouseout="this.className='listRowA'">
<span class="listCol2"><img src="../Content/Images/20_thumb.jpg" width="281" height="200" border="0" alt="image" /></span></div>
</td>
</tr>
<tr>
<td> </td>
<td></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<!-- END -->
</td>
</table>
<!-- END OF MAIN TABLE -->
}
</body>
Instead of
@foreach (var item in Model)
use
@for (var i=0; i < Model.Count; i+=2)
{
}
and access properties of model like
@Model[i].ID
In order to determine which should go to right which should go left you can use
@Model[i].ID for left
and
@if(i+1 < Model.Count)
{
Model[i+1].ID for right
}
Just make sure that i+1
is never more than Model.Count
这篇关于我怎么能遍历我的表在MVC的Razor视图显示由侧方的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!