Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

as of right now I am validating checkbox list in the model by overriding the IsValid function so it will get validated on the server-side, but I was wondering if there's a way to add validation on the client-side. Thank you.

share|improve this question
No problem. Here to help... – Philip Gullick 19 hours ago

1 Answer

You can use jquery validate unobtrusive script. For this you would require to put DataAnnotation attributes to your model class

something like following

public class Model
{
    [Required(ErrorMessage="Name is required")]
    [StringLength(50, ErrorMessage = "Name can not be greater than 50")]
    public string Name{ get; set; }
}

And include the following scripts in your view

<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script>
share|improve this answer
I have done that and I thought the same that adding the required attribute will validate the checkbox list, but for some reason it doesn't. – atang 18 hours ago
okay, I understand your problem. Is it like selecting one of the checkbox ? – Anand 18 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.