views:

60

answers:

1

I am use DataAnnotations validation, it work perfectly but when I validate empty text box field I have error

The value '' is invalid

how can I customize this error?

p.s. error shows only when clients script are off

+1  A: 

You can specify the error message in your DataAnnotations attribute. For example, take the following view model:

public class ViewModel
{
    [Required(ErrorMessage = "You must enter a name")]
    public string Name { get; set; }
}

When that gets validated, it will give "You must enter a name" as the error message to the user.

Greg Shackles