Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用 DataAnnotations 验证,它工作得很好但是当我验证空文本框字段时出现错误
值“”无效
如何自定义此错误?
ps 错误仅在客户端脚本关闭时显示
您可以在 DataAnnotations 属性中指定错误消息。例如,采用以下视图模型:
public class ViewModel { [Required(ErrorMessage = "You must enter a name")] public string Name { get; set; } }
验证后,它将向用户提供“您必须输入名称”作为错误消息。