带有远程数据注释的双重错误消息mvc 5

时间:2015-05-05 09:19:54

标签: asp.net-mvc double data-annotations

嗨,我是MVC的新手,我正在尝试使用远程数据注释和其他字段来验证姓名和姓氏。一切都很好,但是当名称和姓氏已经存在时,我收到双重错误消息。我该如何解决这个问题?

这是我的数据注释:

    [DisplayName("Client Name")]
    [Remote("CheckClient", "Client", HttpMethod = "POST", ErrorMessage = "Client already exists.", AdditionalFields = "ClientLastName, initClientName, initClientLastName")]
    [MaxLength(45, ErrorMessage = "Client Name can not be over 45 characters.")]
    public string ClientName { get; set; }

    [DisplayName("Client Last Name")]
    [Remote("CheckClient", "Client", HttpMethod = "POST", ErrorMessage = "Client already exists", AdditionalFields = "ClientName, initClientName, initClientLastName")]
    [MaxLength(45, ErrorMessage = "Client Last Name can not be over 45 characters.")]
    public string ClientLastName { get; set; }

1 个答案:

答案 0 :(得分:0)

我刚刚修复了问题我刚删除了lastName上的远程注释,功能仍然相同,但第二个错误被删除了。我以为我必须在第二个字段上添加相同的注释以进行验证。