How to require a checkbox to be checked at client side before form gets submitted to server in MVC 3?

Posted by Projapati on Stack Overflow See other posts from Stack Overflow or by Projapati
Published on 2011-06-21T08:09:36Z Indexed on 2011/06/21 8:22 UTC
Read the original article Hit count: 120

I have a Terms and Condition checkbox on my signup page. I want to make it required like my few other fields on the form before posting to server. This validation must be done at client side.

Anyone knows how to do it properly?

I am using MVC 3, jquery.validate.min.js and jquery.validate.unobtrusive.min.js

Model:

[Required(ErrorMessage = "terms and condition")]
[Display(Name = "terms")]
public bool Terms { get; set; }

View:

@Html.CheckBoxFor(m => m.Terms, new { @class = "cb" }) Terms & Condition
<button type="submit" id="btnSubmit" class="btn">Signup</button>

Also, Is it possible to call/trap some JS function when the submit button is clicked? That way I can easily use jquery to do validation and then submit?

Thanks for reading

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about asp.net-mvc-3