【问题标题】:How can I get DataAnnotations.Compare to compare properties from 2 different objects?如何获取 DataAnnotations.Compare 来比较 2 个不同对象的属性?
【发布时间】:2019-02-14 11:50:09
【问题描述】:

我在使用下面的视图时遇到错误

找不到属性 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和passwordConfirm的代码

编辑:我要比较的 2 个属性位于不同的对象中。提议的重复问题中的属性在同一个对象中

【问题讨论】:

标签: c# compare data-annotations


【解决方案1】:

您是否尝试为此创建一个方法,将两个值都分配给字符串,然后比较它们并返回一个布尔值作为结果?

【讨论】:

猜你喜欢
  • 2022-10-16
  • 2023-03-10
  • 2021-05-08
  • 1970-01-01
  • 2017-05-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多