How to handle Booleans/CheckBoxes in ASP.NET MVC 2 with DataAnnotations?

后端 未结 12 1152
慢半拍i
慢半拍i 2020-12-04 10:09

I\'ve got a view model like this:

public class SignUpViewModel
{
    [Required(ErrorMessage = \"Bitte lesen und akzeptieren Sie die AGB.\")]
    [DisplayName         


        
12条回答
  •  温柔的废话
    2020-12-04 10:16

    For people who are having trouble getting this working for validation on the client side (formerly me): make sure you have also

    1. Included <% Html.EnableClientValidation(); %> before the form in the view
    2. Used <%= Html.ValidationMessage or Html.ValidationMessageFor for the field
    3. Created a DataAnnotationsModelValidator which returns a rule with a custom validation type
    4. Registered the class deriving from DataAnnotationsModelValidator in the Global.Application_Start

    http://www.highoncoding.com/Articles/729_Creating_Custom_Client_Side_Validation_in_ASP_NET_MVC_2_0.aspx

    is a good tutorial on doing this, but misses step 4.

提交回复
热议问题