Hi! I have ValidationAttribute like:
public class Username : ValidationAttribute
{
public override bool IsValid(object value)
{
if (value == null)
return false;
return RegExp.Validate(RegExpLib.Username,value.ToString());
}
}
..and using it like this:
public class AccountSignIn
{
[Username(ErrorMessageResourceName ="txtUsername",ErrorMessageResourceType=typeof(SignIn))]
public string Username { get; set; }
public string Password { get; set; }
public bool RememberMe { get; set; }
public string ReturnUrl { get; set; }
}
SignIn is resource file at App_GlobalResources and "txtUsername" - is string name in resource file.
Problem: Error messages are not shown.
Question: How to set error message if I have few languages on the website.
Another info: Im able access SignIn.txtUsername from Views or any file in the project. From controller ModelState.AddModelError("Username", Resources.SignIn.txtUsername); works fine as well.. I can assign ErrorMessage inside ValidationAttribute, but got error after second validation try... if I place check like this - if(ErrorMessage != Resources.SignIn.txtUsername) ErrorMessage = Resources.SignIn.txtUsername; - I have error after I switch to another language - ErrorMessage can be assigned only once.
Please advice how I can solve it.
Thank you in advance.