mardi 25 août 2015

ViewModel replacement for complex Anonymous Object

So im working with this complex anonymous object

        var result = new 
            {    
                percentage = "hide",
                bullets = (string)null,
                item = new [] {
                    new {
                        value = 16,
                        text = "Day",
                        prefix = (string)null,
                        label = (string)null
                    },
                    new {
                        value = 41,
                        text = "Week",
                        prefix = (string)null,
                        label = (string)null
                    },
                    new {
                        value = 366,
                        text = "Month",
                        prefix = (string)null,
                        label = (string)null
                    }
                }
            };

And I want to convert it into a ViewModel and return it as JSON from a rest API.

What I would like to know is

  1. How do I represent this as a model including the array item entries
  2. How do I then add array items to the array once an instance of the model is created
  3. Does the model need a constructor to initialize the array.

Any help or examples you could provide would be great.

Aucun commentaire:

Enregistrer un commentaire