In my Get method of my REST service,
public HttpResponseMessage Get()
{
CustomerRepository lr = new CustomerRepository ();
IQueryable<Customer> data = lr.GetCustomer();
var resp = new HttpResponseMessage(HttpStatusCode.OK);
resp.Content = new ObjectContent<IQueryable<Customer>>(data, new JsonMediaTypeFormatter());
return resp;
}
the following test example would be returned to the view as a json string:
{ id: '1', name:'California', type:'Student', parent:''}, //parent row
{ id: '2', name:'Harry', type:'Student', parent: '1' },
{ id: '3', name:'James', type:'Student', parent: '1' },
{ id: '4', name:'Sally', type:'Student', parent: '1'},
how do I remove the parent row's parent field to be like so before I send it back to UI:
{ id: '1', name:'California', type:'Student'}, //parent row
{ id: '2', name:'Harry', type:'Student', parent: '1' },
{ id: '3', name:'James', type:'Student', parent: '1' },
{ id: '4', name:'Sally', type:'Student', parent: '1'},
Thank you!
EDIT:
I found a solution. In my customer class, I just decorate the field.
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string parent { get; set; }