Share via


MvcOptions.SuppressImplicitRequiredAttributeForNonNullableReferenceTypes Property

Definition

Gets or sets a value that determines if the inference of RequiredAttribute for properties and parameters of non-nullable reference types is suppressed. If false (the default), then all non-nullable reference types will behave as-if [Required] has been applied. If true, this behavior will be suppressed; nullable reference types and non-nullable reference types will behave the same for the purposes of validation.

public:
 property bool SuppressImplicitRequiredAttributeForNonNullableReferenceTypes { bool get(); void set(bool value); };
public bool SuppressImplicitRequiredAttributeForNonNullableReferenceTypes { get; set; }
member this.SuppressImplicitRequiredAttributeForNonNullableReferenceTypes : bool with get, set
Public Property SuppressImplicitRequiredAttributeForNonNullableReferenceTypes As Boolean

Property Value

Remarks

This option controls whether MVC model binding and validation treats nullable and non-nullable reference types differently.

By default, MVC will treat a non-nullable reference type parameters and properties as-if [Required] has been applied, resulting in validation errors when no value was bound.

MVC does not support non-nullable reference type annotations on type arguments and type parameter constraints. The framework will not infer any validation attributes for generic-typed properties or collection elements.

Applies to