3

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

  • 当有一个项目时,我只希望显示该项目。(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>

感谢您的帮助!

4

1 回答 1

6

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...
}
于 2012-09-11T14:52:06.383 回答