title: How to return only some fields to json response in asp.net web api
body: <p>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,</p>
  
  <pre><code>public List&lt;MyTable&gt; GetRecords()
  {
  return context.mytable.ToList();
  }
  </code></pre>
  
  <p>and i got the response like,</p>
  
  <pre><code>[{"field1":true,"field2":false,"field3":true,"field4":false}]
  </code></pre>
  
  <p>Now i need to get only the fields whose value true so the above response will be like,</p>
  
  <pre><code>[{"field1":true,"field3":true}]
  </code></pre>
  
  <p>I have tried with [JsonIgnore] attribute but it con be used only at the time of model class creation like,</p>
  
  <pre><code>[JsonIgnore]
  public string field1{get; set;}
  </code></pre>
  
  <p>How could i programatically apply jsonignore on the fields so that i can able return only specified fields. please guide me.</p>