Specifies that JavaScriptSerializer will not serialize the public property or public field. This class cannot be inherited.
Syntax
CSharp
VisualBasic
ManagedCPlusPlus
JSharp
Members
Remarks
If you apply ScriptIgnoreAttribute to a public property or public field of a class, then JavaScriptSerializer ignores, or skips, the member when serializing an instance of the class to JSON format.
The ScriptIgnoreAttribute will have no effect if the ResponseFormat property is set to Xml. If you want to have the same behavior when serializing to XML format, XmlIgnoreAttribute should be applied to the property or field instead. This is because the class will be serialized by using XmlSerializer instead of JavaScriptSerializer.
You can also apply both ScriptIgnoreAttribute and XmlIgnoreAttribute to a property or field. In this case, the property or field will be ignored for JSON and XML response formats.
For more information about how to use attributes, see Extending Metadata Using Attributes.
Examples
The following example demonstrates how to apply ScriptIgnoreAttribute to the Comment field in the custom class named Group. This instructs JavaScriptSerializer to ignore the field when serializing an instance of the class to JSON format.
App_Code
using System;
using System.Web.Script.Serialization;
public class Group
{
// The JavaScriptSerializer ignores this field.
[ScriptIgnore]
public string Comment;
// The JavaScriptSerializer serializes this field.
public string GroupName;
}
App_Code
Imports Microsoft.VisualBasic
Imports System.Web.Script.Serialization
Public Class Group
' The JavaScriptSerializer ignores this field.
<ScriptIgnore()> Public Comment As String
' The JavaScriptSerializer serializes this field.
Public GroupName As String
End Class
Permissions
Inheritance Hierarchy
Assembly: System.Web.Extensions (Module: System.Web.Extensions)