kusanagi
kusanagi

Reputation: 14624

mvc 2.0 validation

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

Upvotes: 0

Views: 115

Answers (1)

Greg Shackles
Greg Shackles

Reputation: 10139

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.

Upvotes: 1

Related Questions