razor count items
15,624
Razor is in effect C#, so anything you can do with C#, you can do with Razor. Something like this should work:
@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...
}
Author by
RunnicFusion
Updated on June 04, 2022Comments
-
RunnicFusion almost 2 years
How can i do this in razor:
- when there is one item, i only want this item to be displayed. (item in fotoGallerij)
- when there are more items, i want all of them (like the code bellow, working)
How can i make this if (i think) structure in razor (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&constrain=true&crop=resize&[email protected]" title=""> <img src="/ImageGen.ashx?width=71&height=73&crop=resize&[email protected]" alt=""/></a> </li> } </ul> <script> $("a.gallery").colorbox({rel:'grouped'}); </script>
Thanks for helping!
-
Jules Bartow about 11 yearsCompiler Error Message: CS1061: 'MVCApp3.Models.CompanyListView' does not contain a definition for 'Count' and no extension method 'Count' accepting a first argument of type 'MVCApp3.Models.CompanyListView' could be found (are you missing a using directive or an assembly reference?)
-
Douglas Ludlow about 11 years@JulesBartow, the code above is in reference to umbraco. Model.fotoGallerij is handled by umbraco dynamically and returns a DynamicNodeList which does have a Count method associated with it. This wouldn't apply to a standard MVC app.