0

I Have a model in ASP.Net MVC something like this one.

public class DataTable
        {
            public int RecordsTotal { get; set; }

            public int RecordsFiltered { get; set; }

            public int Draw { get; set; }

        }

It is possible to output this as a JSON with putting a Data Annotation in every property? The output should be something like this.

{
recordsTotal:10,
recordsFiltered:10,
draw:1 
}

Thanks!

jmvtrinidad
  • 3,347
  • 3
  • 22
  • 42

1 Answers1

2

You can return an object that looks exactly like the one you posted aside from the capital letter at the beginning:

return Json(new DataTable() {
    RecordsTotal = 10,
    RecordsFiltered = 10,
    Draw = 1
});

If you really need a lowercase property name then there are existing questions that answer this.

Community
  • 1
  • 1
Justin Helgerson
  • 24,900
  • 17
  • 97
  • 124