Skip to content

NullReferenceException in ValidationAttribute. #39

@MikhailPikhota

Description

@MikhailPikhota

How i may a valigate attribute?
Some changes to your example and have a NullReferenceException in non-default language:

[Localized]
public class LogOnModel
{
    [Required]
    [ValidateUserNameUnique]
    [Display(Name = "User name")]
    public string UserName { get; set; }
...
}
public class ValidateUserNameUnique : ValidationAttribute
{
    protected override ValidationResult IsValid(object value, ValidationContext validationContext)
    {
        var userName = value as string;
        return ValidationResult.Success;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions