-
Notifications
You must be signed in to change notification settings - Fork 3
8. Excluding properties
In Umbraco DocumentTypes can inherit properties from a parent type. The generated class inherits from ModelBase, not from a parent DocumentType model. However, the class inherits all the properties specified in the parent DocumentType model. You might not always want this. For example are the general properties which are used for SEO optimization. If these properties are normally defined at a base DocumentType level and other types will inherit those properties. This might not be desired and might pollute the model with properties you don’t want.
You can exclude properties from being generated into model properties by specifying a regex that will filter all unwanted properties by alias. You have to modify the Models.tt T4 template to do this. Fortunately this is easy to do: modify the line Code.ExcludePropertyRegEx = "";
And add a proper regex. Example:
Code.ExcludePropertyRegEx = "^seo|^openGraph";
When you want to return model data in JSON format, as a result of an Ajax call, you don’t want to return property values which are not used in the view. Decorate the property with the ScriptIgnore attributre and this property will not be serialized into the JSON output. Example:
[ScriptIgnore()]
public string NotInJsonOutputProperty { get; set; }