Classes in razor engine template

后端 未结 3 1790
我寻月下人不归
我寻月下人不归 2021-01-01 12:07

Is it possible to create classes within a template? Something like...

@{
    public class MyClass {
        public MyClass() {
            Three = new List&l         


        
3条回答
  •  鱼传尺愫
    2021-01-01 12:21

    I would suggest using a specific ViewModel class, which could have a dynamic property (ExpandoObject) allowing you to populate it with any custom data structure as needed while still communicating strongly typed for whatever else your view might need.

    This also keeps your view models separate from the views themselves, which is good practice (html and code don't mix too well where readability is a concern).

提交回复
热议问题