MvcOptions.SuppressImplicitRequiredAttributeForNonNullableReferenceTypes 屬性

定義

取得或設定值,這個值會判斷是否隱藏不可為 Null 之參考型別之屬性和參數的推斷 RequiredAttribute 。 如果 false (預設) ,則所有不可為 Null 的參考類型都會如已套用一 [Required] 樣運作。 如果 true 為 ,則會隱藏此行為;可為 Null 的參考型別和不可為 Null 的參考型別在驗證時的行為會相同。

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

屬性值

備註

此選項可控制 MVC 模型系結和驗證是否以不同方式處理可為 Null 和不可為 Null 的參考類型。

根據預設,MVC 會將不可為 Null 的參考型別參數和屬性視為 [Required] 已套用,並在未系結任何值時產生驗證錯誤。

MVC 不支援類型引數和類型參數條件約束上不可為 Null 的參考型別注釋。 架構不會推斷泛型屬性或集合專案的任何驗證屬性。

適用於