Class/Model Level Validation (as opposed to Property Level)? (ASP.NET MVC 2.0)

后端 未结 6 2166
忘掉有多难
忘掉有多难 2020-12-14 10:31

Basically, what the title says. I have several properties that combine together to really make one logical answer, and i would like to run a server-side validation code (tha

6条回答
  •  天涯浪人
    2020-12-14 11:38

    Possible Dupe:

    Writing a CompareTo DataAnnotation Attribute

    The answers to your questions should be there and at the very least it points to this blog post:

    http://byatool.com/mvc/custom-data-annotations-with-mvc-how-to-check-multiple-properties-at-one-time/


    To get the error message to display you must use:

    <%: Html.ValidationMessage("") %>
    

    What happens is because your validating on a class level your getting a ModelState with a key, aka property name usually, with an empty string.

提交回复
热议问题