2

I'm using MVC Controller. Json method in order to send json result object to my javascript function.

From time to time I want to omit one of my object's property from the json result object.

How can I achive it?

This is my .NET object:

    public class jsTreeModel
    {
        public string Data { get; set; }
        public JsTreeAttribute Att { get; set; }
        public string State { get; set; }
        public List<jsTreeModel> Children { get; set; }
    }

I this case I want to omit the 'Children' property from the json result.

Any idea?

Triad sou.
  • 2,969
  • 3
  • 23
  • 27
Yair Nevet
  • 12,725
  • 14
  • 66
  • 108
  • 1
    Looks like a dupe of http://stackoverflow.com/questions/372955/best-way-to-filter-domain-objects-for-json-output-in-an-asp-net-mvc-application – JoshNaro Sep 23 '11 at 15:52

1 Answers1

0

If you are using Json.NET as your serializer, you can omit a property fairly simply:

public class jsTreeModel
{
    public string Data { get; set; }
    public JsTreeAttribute Att { get; set; }
    public string State { get; set; }
    [JsonIgnore]
    public List<jsTreeModel> Children { get; set; }
}

I hope this helps you!

Connie Hilarides
  • 1,685
  • 15
  • 13