Classes in razor engine template

Yes, this is completely possible. Use the @functions keyword:

@functions {
    public class MyClass {
        public MyClass() {
            Three = new List<string>();
        }

        public string One { get; set; }
        public int Two { get; set; }
        public List<string> Three { get; set; }
    }
}

Leave a Comment