ValidationContext.MemberName 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定成員名稱以進行驗證。
public:
property System::String ^ MemberName { System::String ^ get(); void set(System::String ^ value); };
public string MemberName { get; set; }
member this.MemberName : string with get, set
Public Property MemberName As String
屬性值
成員姓名以供驗證。
備註
此屬性代表實體成員名稱,而非對應資料欄位的名稱。 因此,這個名稱並非本地化。 它應該只設定在屬性或參數上下文中。
在 .NET Framework 4.7.2 和舊版中,使用自定義 System.ComponentModel.DataAnnotations.ValidationAttribute時,屬性 MemberName 會傳 null回 。 從 .NET Framework 2019 年 10 月品質整合預覽版 .NET開始,若你將以下設定加入 web.config 檔案,該屬性會回傳成員名稱:
<configuration>
<appSettings>
<add key="aspnet:GetValidationMemberName" value="true" />
</appSettings>
</configuration>
若無此設定,.NET該屬性會在 2019 年 10 月的 Framework 預覽版品質整合或更新版本中回傳 null。
在 2019 年 10 月更新前的 .NET Framework 4.8 版本中,此屬性會回傳成員名稱,但未包含設定設定。 如果你像前述範例所示更改 web.config 檔案,屬性會回傳 null。