ASP MVC: Custom Validation Attribute

前端 未结 7 976
说谎
说谎 2021-01-18 10:00

I\'m trying to write my own Custom Validation attribute but I\'m having some problems.

The attribute I\'m trying to write is that when a user logs in, the password w

7条回答
  •  攒了一身酷
    2021-01-18 10:28

    FoolProof http://foolproof.codeplex.com/ seems to be the best solution.

    public class SignUpViewModel
    {
        [Required]
        public string Password { get; set; }
    
        [EqualTo("Password", ErrorMessage="Passwords do not match.")]
        public string RetypePassword { get; set; }
    }
    

    It is better than suggested PropertiesMustMatchAttribute as it adds the validation error for the "RetypePassword' instead of the global model level as PropertiesMustMatchAttribute does.

提交回复
热议问题