Omit object property during json serialization
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 JsTree开发者_运维问答Attribute 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?
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!
精彩评论