c# - How to use compare attribute to validate new password?
问题描述
Here is the code:
public string NewPassword { get; set; }
public string NewPasswordConfirm { get; set; }
public string NewFirstName { get; set; }
public string NewLastName { get; set; }
public AccountSettingsViewModel()
{
Title = "Account";
}
I'm trying to make sure that the new password and new password confirm are the same using the Compare Attribute. How would i go about doing this?
解决方案
您可以使用Compare DataAnnotation,参数将是模型中的 Password 属性。
[Required]
public string NewPassword { get; set; }
[Compare("NewPassword")]
public string NewPasswordConfirm { get; set; }
推荐阅读
- r - 如何使用 R 组织 MLE 的输出(重复)
- c# - 使用 C# XmlSerializer 优化矩形序列化
- c++ - 衡量比较两个解决方案的执行效率?
- python - 熊猫中元素和行条件之间的逻辑与(布尔值以及矩阵和列之间)
- c# - 是否可以从另一个类库中的静态类中获取 ConnectionString?
- apache - 使用 Apache 2.4.41 的 samba 共享上的服务目录会截断标头
- wpf - WebView2 - 改善加载时间和/或考虑替代方案
- assembly - 接受来自控制台的数据
- python - 错误消息 - 在 pythonanywhere 上部署 python 项目
- r - 引用不存在的列表元素时会发生什么?