简体   繁体   中英

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

I'm getting an error using the view below

The property Models.m_Join.Member.password could not be found.

The 'Password' field that the error refers to is part of the 'member' object that is in the m_Join model.

I've tried using : -

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

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

But neither of them work.

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; }


}

What do I have to use to get the code to compare member.password and passwordConfirm

Edit: The 2 properties I want to compare are in different objects. The properties in the proposed duplicate question are in the same object

您是否尝试过为此创建一个方法,该方法将两个值都分配给字符串,然后进行比较并返回一个布尔值?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM