开发者

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


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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜