Razor 剃刀计数项目

Razor 剃刀计数项目,razor,count,umbraco,if-statement,Razor,Count,Umbraco,If Statement,如何在razor中执行此操作: 当有一个项目时,我只希望显示该项目。(fotoGallerij中的项目) 当有更多项目时,我想要所有项目(如下面的代码,工作) 如果(我认为)razor(c#/umbraco)中的结构是这样的,我该怎么做 @继承umbraco.MacroEngines.dynamicontext @foreach(var项目在@Model.fotoGallerij中) { } $(“a.gallery”).colorbox({rel:'grouped'}); 谢谢你

如何在razor中执行此操作:

  • 当有一个项目时,我只希望显示该项目。(fotoGallerij中的项目)
  • 当有更多项目时,我想要所有项目(如下面的代码,工作)
如果(我认为)razor(c#/umbraco)中的结构是这样的,我该怎么做

@继承umbraco.MacroEngines.dynamicontext
    @foreach(var项目在@Model.fotoGallerij中) {
  • }
$(“a.gallery”).colorbox({rel:'grouped'});
谢谢你的帮助

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...
}

仅1个项目的所需标记相同吗?换言之,你希望它看起来像什么,只有一个?因为如果只有一个,您的原始代码应该仍然可以很好地显示它。如果只有一个图像,我希望这一个更大并带有链接(allready完成了).Compiler错误消息:CS1061:“MVCApp3.Models.CompanyListView”不包含“Count”的定义,并且找不到接受“MVCApp3.Models.CompanyListView”类型的第一个参数的扩展方法“Count”(是否缺少using指令或程序集引用?)@JulesBartow,上面的代码引用了umbraco。Model.fotoGallerij由umbraco动态处理,并返回一个DynamicDelist,该DynamicDelist具有与其关联的计数方法。这不适用于标准的MVC应用程序。
@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...
}