Developer forum

Forum » Templates » Razor Foreach with Itemlist

Razor Foreach with Itemlist

Nuno Aguiar
Reply

Hi,

 

We've got an Item value from the area. That Item (Alert types) is an Item List. How can we loop through that ItemList to match the value we need? We are actually loading all of the items from that table to match the value we need.

 

We tried to instance an Item Collection but get the error Using the generic type 'Dynamicweb.Content.Items.Collection' requires 1 type arguments

 

Please check attachment.

 

Quick view:

var obj_alertTypes = Collection("Alert_Type");

foreach (LoopItem i in GetLoop("Rows")){

    foreach (var alert in obj_alertTypes){
      if(alert.GetValue("Id") == i.GetValue("AlertType")){
        var str_alertCssClass = alert.GetValue("CssClass");
        break;
      }

}

 

Nuno


Replies

 
Mikkel Ricky
Reply

Sorry for the late reply.

In Dynamicweb 8.4.1, you have a loop for each item list on an item, e.g.

@foreach (var alert in GetLoop("Item.Area.Alerts")) {
  <div class='alert alert-@alert.GetValue("Item.Area.Alerts.Type")'>
    @alert.GetValue("Item.Area.Alerts.Message")
 </div>
}

Is that what you're asking for? Or are you asking (more generally) how to load items?

Best regards,
Mikkel

 

 
Nuno Aguiar
Reply

Hi Mikkel,

 

If we have a new loop, it solves the issue :)

 

For a generic approach we will use 8.4.1 the RenderItemList solution

 

Thanks,

Nuno

 

You must be logged in to post in the forum