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!

4
  • What data annotations would you like to add, exactly? Commented May 29, 2015 at 2:08
  • Data annotation that will transform RecordsTotal into a key recordsTotal. When returning a json to client/browser. Commented May 29, 2015 at 2:10
  • Is the only difference here capitalization? Otherwise, returning a JSON object will take care of that by default: { RecordsTotal:10, RecordsFiltered:10, Draw:1 } Commented May 29, 2015 at 2:13
  • Yes, the only thing that I want is returning it as a CamelCase. Commented May 29, 2015 at 2:16

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.