0

I need to pass this list to my view: enter image description here

But in this format:

{
  "data": [
    {
      "FIRST_NAME": "Robert",
      "LAST_NAME": "Meczybula",
      "ID": 12421
       ...
     },
...
]}
DiPix
  • 5,069
  • 10
  • 54
  • 97
  • Possible duplicate of [How to return Json object from MVC controller to view](http://stackoverflow.com/questions/15196528/how-to-return-json-object-from-mvc-controller-to-view) – Shaharyar Jun 14 '16 at 19:13

1 Answers1

1

Basically you want to transform your list to the desired data contract. Linq is good for this:

var transform = new
    {
        data = data.Select(x => 
            new {
                x.FIRST_NAME,
                x.LAST_NAME,
                ...
            }),
        ...
    };

Then just serialize and return the transform object.

aelstonjones
  • 372
  • 2
  • 7
  • 25