dimanche 2 août 2015

How do i put validation on checkbox with MVC3 razor?

I have created the register page on mvc3 razor. I want to put the validation on user notification field. Below is my code.

 [Required]
 [Display(Name = "Student Notification ?")]
 [Range(typeof(bool), "true", "true", ErrorMessage = "You gotta tick the box!")]
 public Boolean UserNotification { get; set; }

Below is my register page view

<div class="editor-label">
        @Html.LabelFor(model => model.UserNotification)
    </div>
    <div class="editor-label">
        @Html.CheckBoxFor(model =>model.UserNotification)
        @Html.ValidationMessageFor(model => model.UserNotification)
    </div>
     <p>
        <input type="submit" value="Register" />
    </p>

So when i will click the button, there should be validation message there ..

Aucun commentaire:

Enregistrer un commentaire