Property-level validation errors hinder the validation of Class-level validation

后端 未结 3 2203
难免孤独
难免孤独 2020-12-18 05:15

Update after Bounty was awarded

A new solution is coming up to this problem. Please refer to ASP.NET MVC 3 Preview 1 here: http://weblogs.asp.net/sc

3条回答
  •  佛祖请我去吃肉
    2020-12-18 05:46

    From your example, that you like to have a "confirm other input box entry" boxes, the correct implementation would be

     [EqualTo("Email", ErrorMessage = "E-mailadresserne skal være ens")]
     public string EmailConfirm { get; set; }
    

    as the "error" is a validation of the Confirm box. or in other words, you would like to have the Error message next to the confirm box, saying its not the same as in the Email box.

    this puts the validation configuration back to the property, and solving your issue.

提交回复
热议问题