Ignoring a field during .NET JSON serialization; similar to [XmlIgnore]?

后端 未结 4 732
鱼传尺愫
鱼传尺愫 2020-11-30 05:38

I have a POCO class that is being sent to the browser as a JSON string in .NET 3.5 sp1. I am just using the default JSON serialization and I have some fields that I want to

4条回答
  •  伪装坚强ぢ
    2020-11-30 05:50

    You just need to add the [ScriptIgnore(ApplyToOverrides = true)] into your text template (.tt) file.

    Here a portion of my text template before

    #>
    <#=codeStringGenerator.NavigationProperty(navigationProperty)#>
    <#
    

    Once I inserted the code the line above the codeStringGenerator my classes auto generated and looked like this:

    [ScriptIgnore(ApplyToOverrides = true)]
    public virtual ICollection Currencies { get; set; }
    

    I also needed to modify the UsingDirectives function to insert "using System.Web.Script.Serialization;"

提交回复
热议问题