I am working on asp.net mvc 4 web api. I am trying to return list of records as a json response. my table contains four fields field1,field2,field3 and field4 and i write the action like,
public List<MyTable> GetRecords()
{
return context.mytable.ToList();
}
and i got the response like,
[{"field1":true,"field2":false,"field3":true,"field4":false}]
Now i need to get only the fields whose value true so the above response will be like,
[{"field1":true,"field3":true}]
I have tried with [JsonIgnore] attribute but it con be used only at the time of model class creation like,
[JsonIgnore]
public string field1{get; set;}
How could i programatically apply jsonignore on the fields so that i can able return only specified fields. please guide me.