Razor: Why is my variable not in scope

后端 未结 2 1166
情书的邮戳
情书的邮戳 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:28

    Define the variable in a @functions section.

    The normal @{ places your code in some method body. Use @functions to define class members.

    @functions{ List qa = new List(); } 
    

    More reading on this matter: SLaks Dissecting razor series.

提交回复
热议问题