[ACCEPTED]-How to mark a property as non serializable for json?-asp.net-mvc

Accepted answer
Score: 21

I think you just want to apply the ScriptIgnoreAttribute:

public string IgnoreThis { get; set; }


Score: 12

If you are needing this for ASP.NET Core or even before 2 that, you should be using:


you'll need to 1 reference:

using Newtonsoft.Json;
Score: 0

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