【问题标题】:Customize asp.net mvc validation error message自定义asp.net mvc验证错误信息
【发布时间】:2015-04-08 08:17:07
【问题描述】:

我创建了这个模型类:

 public class test5
{
    [Required] //when title field empty send from client this is show this messae" The title field is required."
    public string title { get; set; }
    public int content { get; set; }
}

我想将必填字段错误消息编辑为自定义消息,当我使用 [Required] 之类的验证时,任何地方都会显示该错误消息。我该怎么做?

【问题讨论】:

    标签: asp.net-mvc validation model-view-controller


    【解决方案1】:

    在数据注释中使用关键字ErrorMessage

    public class test5
    {
    [Required(ErrorMessage = "CUSTOM ERROR MESSAGE")]
        public string title { get; set; }
        public int content { get; set; }
    }
    

    【讨论】:

    猜你喜欢
    • 2011-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-25
    • 1970-01-01
    • 2016-10-21
    • 2021-08-12
    • 2021-12-09
    相关资源
    最近更新 更多