Asp.Mvc 2.0用户登录实例讲解---(4)服务器端验证(4)
{
PWD = pwd;
ConfirmPwd = confirmPwd;
}
/// <summary>
/// 返回错误的提示信息
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public override string FormatErrorMessage(string name)
{
return ErrorMessage;
}
/// <summary>
/// 重写TYPEID
/// </summary>
public override object TypeId
{
get
{
return _typeid;
}
}
/// <summary>
/// 判断是否想到
/// </summary>
/// <param name="value">value的值实际上是MODEL提交的MODEL类</param>
/// <returns></returns>
public override bool IsValid(object value)
{
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(value);
object originalValue = properties.Find(PWD, true ).GetValue(value);//获取密码
object confirmValue = properties.Find(ConfirmPwd, true).GetValue(value);//获取确认密码的值
return Object.Equals(originalValue, confirmValue);
}
}
PwdMatch属性类创建后,可把它标记在注册MODEL的上面,然后提交注册的时候,就会验证了
[PwdMatch("UserPwd","ConfirPwd", ErrorMessage ="密¨¹码?与®?确¨¡¤认¨?不?匹£¤配?")]
相关新闻>>
- 发表评论
-
- 最新评论 更多>>