[ACCEPTED]-How to mark a property as non serializable for json?-asp.net-mvc
I think you just want to apply the ScriptIgnoreAttribute
:
[ScriptIgnore]
public string IgnoreThis { get; set; }
0
If you are needing this for ASP.NET Core
or even before 2 that, you should be using:
[JsonIgnore]
you'll need to 1 reference:
using Newtonsoft.Json;
As of .NET 3.0, you can use DataContract instead of 11 Serializable. With the DataContract though, you 10 will need to either "opt-in" by 9 marking the serializable fields with the 8 DataMember attribute; or "opt-out" using 7 the IgnoreDataMember.
The main difference between opt-in 6 vs opt-out is that opt-out by default will 5 only serialize public members, while opt-in 4 will only serialize the marked members (regardless 3 of protection level).
Note that if you are 2 using Newtonsoft.Json for your serialization 1 (like in my case), it supports DataContract as well.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.