Developer forum

Forum » Templates » Razor, how to check if loop is empty?

Razor, how to check if loop is empty?

Jacob Storgaard Jensen
Reply

Hi guys,

I have an item with an item list on it (Images).

But when the item list is empty it still appears in Loops, so this:

@if (Loops.Contains("Item.Images")) {
<div>
  foreach here...
</div>
}

does not work to avoid my wrapping div beeing output... How do you do this in Razor?


Replies

 
Viktor
Reply
This post has been marked as an answer

Greetings. We really appreciate your appeal and will try to do anything to help you. 

Looks like there is no specific function to chekc if any item list items exists, but i can suggets you use next construction for it:


@if(!string.IsNullOrEmpty(GetString("Item.Images.Value"))){
   <div> foreach here... </div>
      }


I guess it will help you with your task. If not - add some details here and i'll try to help you.

 

Best regards,
Viktor Letavin
DynamicWEB Software A/S, Russian team
Votes for this answer: 1
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

What are you for-eaching over? Can't you check for Any() or Count == 0?

Imar

 
Jacob Storgaard Jensen
Reply

Hi guys,

The one Viktor suggested worked fine :-)

Thanks

 

You must be logged in to post in the forum