The following attributes affect the validation process of your View.
[Required(ErrorMessage = "Password cannot be blank.")]
[StringLength(20, MinimumLength = 3)]
For the Validation attributes, you can create a class like this:
public class PasswordRuleAttribute : ValidationAttribute
{
public override bool IsValid(object value)
{
if (new RequiredAttribute { ErrorMessage = "Password cannot be blank." }.IsValid(value) && new StringLengthAttribute(20) { MinimumLength=3 }.IsValid(value) )
return true;
return false;
}
}
You can use it as follows:
[PasswordRule]
public string Password{get;set;}
The other two attributes that you mentioned are Directly derived from the Attribute
class, and I don't think there's a way to consolidate them into a single attribute.
I'll update you with an edit soon.
So now we're left with:
[DisplayName("Password")]
[DataType(DataType.Password)]
[PasswordRule]
public string Password{get;set;}
EDIT:
According to this post: Composite Attribute, it's not possible to merge attributes.