0

For one of my project requirement, i need to perform validation over some control. (MVC 5 , Data annotation, JQuery)

Looking some different approach, i need data annotation validation handled through JQuery

  I have following control on my page with validation using data annotation on all these control:

  1) Username
  2) EmailId
  3) Contact No
  4) Password
  5) Confirm Password

Initially top 1-3 controls are blocked and and 4-5 control is set to display none So, i need validation should not check for 4-5 when i press submit button.

Later it will show 4-5 control and 1-3 control is set to display none. in that case i need validation should not check for 1-3.

NOTE: There is only one View page, can't have multiple view pages

How can i enable and disable data annotation validation using JQuery.

1 Answer 1

1

i think you are looking for conditional validation. various post for this:-

Model Validation / ASP.NET MVC 3 - Conditional Required Attribute

http://blogs.msdn.com/b/simonince/archive/2011/02/04/conditional-validation-in-asp-net-mvc-3.aspx

http://www.codeproject.com/Articles/541244/Conditional-ASP-NET-MVC-Validation-using-Data-Anno

Client side validation

If you are using jqueryvalidation.js by default it skips validation for hidden and display none element and if you want ignore validation for specific inputs you can do it by:-

$("#form1").validate({
  ignore: "input[type='text']:hidden",
   rules: {
     something: {
         number:true,
         min:1,
         required:true
        }
    }
});
Sign up to request clarification or add additional context in comments.

4 Comments

actually i m looking some different approach, i need dataannotation validation handled through JQuery
@sham so you need only client side condition validation. Am i right?
are you using jquery validation plugin?
ya, without that client side validation not possible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.