Returning Json objects to DataTable (Ajax/MVC)

Returning Json objects to DataTable (Ajax/MVC)

morilonmorilon Posts: 1Questions: 1Answers: 0

Hello there, i'm having trouble returning the json to my view.

When I return it as simple arrays, it works perfectly as

{
  "aaData":[
                    ["USERNAME #1","username1@email.com"],
                    ["USERNAME #2","username2@email.com"]
                 ]
}

BUT.

I need to return something like this in order to work as I want it.

{
  "aaData":[
                    ["username": "USERNAME #1","email": "username1@email.com"],
                    ["username": "USERNAME #2","email": "username2@email.com"]
                 ]
}

Is there a way that I can get this kinda object-return from Json using ASP.NET MVC?

My Controller code:

return Json(new
            {
                aaData = users.Select(x => new string[] { 
                    x.Username, 
                    x.Email, 
                })

            }, JsonRequestBehavior.AllowGet);
This discussion has been closed.