Using Static Variables in Razor

前端 未结 3 2007
清歌不尽
清歌不尽 2020-12-16 11:43

Why is it not possible to use a static Variable from a static class inside a view?

For example, lets say you have a Settings Class:

public static cla         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-16 12:14

    your global class should be like

    public class GlobalVariables
    {
        public static string SystemColor
        {
            get { return Properties.Settings.Default.SystemColor; }
        }
    }
    

    and in page @AppName.GlobalVariables.SystemColor appname replace by namespace of global class

    @using AppName.Models
    
    

    System Color

提交回复
热议问题