Razor: Why is my variable not in scope

后端 未结 2 1163
情书的邮戳
情书的邮戳 2021-02-07 03:37
@inherits umbraco.MacroEngines.DynamicNodeContext
@using System.Collections;

@{ List qa = new List(); } //this is not defined in the recursi         


        
2条回答
  •  走了就别回头了
    2021-02-07 04:14

    In Razor 3.2.3 it seems the variable declared in @functions need to be declared static. Seems unfortunate. Please correct me if there is an alternative way.

    @functions
    {
        static List qa = new List();
    }
    
    @helper traverseFirst(dynamic node)
    {
       var items = node.Children.Where("umbracoNaviHide != true");
       foreach (var item in items) {
         foreach(var subItem in item.Descendants()) {
            if(subItem.Id == Model.Id)
            {
               qa.Add();
               break;
            }
         }
         @traverseFirst(item)
       }
    }
    

提交回复
热议问题