剃刀计数项目

时间:2012-09-11 09:33:51

标签: razor count umbraco if-statement

我怎样才能在剃刀中做到这一点:

  • 当有一个项目时,我只希望显示该项目。 (fotoGallerij中的项目)
  • 当有更多项目时,我想要所有这些项目(如下面的代码,工作)

如何在剃刀(c#/ umbraco)中制作这个(我认为)结构?

@inherits umbraco.MacroEngines.DynamicNodeContext

<ul class="image-gallery">
@foreach (var item in @Model.fotoGallerij)
{
<li>
<a class="gallery grouped" href="/ImageGen.ashx?height=500&amp;constrain=true&amp;crop=resize&amp;image=@item.Image.umbracoFile" title="">

<img src="/ImageGen.ashx?width=71&amp;height=73&amp;crop=resize&amp;image=@item.Image.umbracoFile" alt=""/></a>
 </li>
 }
</ul>
 <script>
    $("a.gallery").colorbox({rel:'grouped'});
</script>

感谢您的帮助!

1 个答案:

答案 0 :(得分:4)

Razor实际上是C#,所以你可以用C#做​​任何事情,你可以用Razor做。这样的事情应该有效:

@inherits umbraco.MacroEngines.DynamicNodeContext
@if (Model.fotoGallerij.Count() == 1)
{
    // Display only the one here...
}
else if (Model.fotoGallerij.Count() > 1)
{
    // Loop through the list of items here...
}
相关问题