razor语法
现在有个很简单的要求
在for或是foreach每二项分一行
核心代码
@{ int cindex = 0 ;}
@foreach (var url in urlgroup.UrlModels.OrderBy(p => p.Order).ToList())
{
cindex++;
//how to do next?
@*
if ( (cindex %2 ) == 1 )
{
<tr>
}
*@
@*
if ( (cindex %2 ) == 1 )
{
</tr>
}
*@
}
------解决方案--------------------
@**@是注释吧
------解决方案--------------------
<table style="width: 100%">
<tr>
@{
int cindex = 0;
var list=urlgroup.UrlModels.OrderBy(p => p.Order).ToList();
foreach (var url in list) {
if (cindex++ % 2 == 0) {
@: </tr> <tr>
}
@: <td>
@url.你的对象
@:</td>
}
@: </tr>
}
</table>
------解决方案--------------------
@{ int cindex = 0 ;}
<table>
@foreach (var url in urlgroup.UrlModels.OrderBy(p => p.Order).ToList())
{
if ( (cindex %2 ) == 0 )
{
<tr>
}
<td></td>
if ( (cindex %2 ) == 1 )
{
</tr>
}
cindex++;
}
</table>