簡體   English   中英

如何獲得DataAnnotations.Compare來比較2個不同對象的屬性?

[英]How can I get DataAnnotations.Compare to compare properties from 2 different objects?

使用以下視圖時出現錯誤

找不到屬性Models.m_Join.Member.password。

錯誤所指向的“密碼”字段是m_Join模型中“成員”對象的一部分。

我試過使用:-

    [System.ComponentModel.DataAnnotations.Compare("member.password", ErrorMessageResourceType = typeof(Resources.errors), ErrorMessageResourceName = "passwordsDontMatch")]

    [System.ComponentModel.DataAnnotations.Compare("member_password", ErrorMessageResourceType = typeof(Resources.errors), ErrorMessageResourceName = "passwordsDontMatch")]

但是它們都不起作用。

public class m_Join
{

    public Member member { get; set; }

    [System.ComponentModel.DataAnnotations.Compare("password", ErrorMessageResourceType = typeof(Resources.errors), ErrorMessageResourceName = "passwordsDontMatch")]
    public string passwordConfirm { get; set; }


}

我必須使用什么來獲取比較member.password和password的代碼

編輯:我要比較的2個屬性在不同的對象中。 建議的重復問題中的屬性在同一對象中

您是否嘗試過為此創建一個方法,該方法將兩個值都分配給字符串,然后進行比較並返回一個布爾值?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM