开发者

mvc 2.0 validation

开发者 https://www.devze.com 2022-12-20 22:09 出处:网络
I am use DataAnnotations validation, it work perfectly but when I validate empty开发者_开发问答 text box field I have error

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消