1

What is the need of following jquery reference script libraries for validation in asp.net MVC?

<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>

And what is the meaning of 'unobtrusive validation'?

haim770
  • 48,394
  • 7
  • 105
  • 133
Siva
  • 25
  • 6
  • 1
    Unobtrusive validation is for client side validation used in conjunction with `@Html.ValidationMessageFor()` to render error messages based on validation attributes (and prevents a form submitting if invalid) –  Feb 05 '15 at 07:52

2 Answers2

0

They come just along as parts of the default templates, you don't need to use any of them if not required. For details about jQuery unobstrusive validation see this thread.

Community
  • 1
  • 1
asp_net
  • 3,567
  • 3
  • 31
  • 58
0

jQuery.js:

Well, this one is an obvious dependency.

jQuery.validate.js:

Is a library that lets you validate forms easily without the need to write the actual validation logic and event handling yourself (as it comes bundled with many 'adapters' such as required, digits, min/max etc), it will automatically prevent form submission and will display the appropriate error message.

For example:

$('#myForm').validate({
    rules: {
           fullname: { required: true, minlength: 5 },
           age: { digits: true, maxlength: 2 },
           }
});

jQuery.validate.unobtrusive.js:

Unobtrusive validation is aiming at sparing you from the need to explicitly set each element's validation rules in an imperative manner but rather lets you define the rules in a declarative way using data-* attributes.

It is called 'unobtrusive' because it lets you write semantic HTML without adding an 'intrusive' <script> tags for each element's desired rules.

For example:

<input type="text"
       name="fullname"
       data-val="true"
       data-val-required="fullname is required"
       data-val-length="minimum 5 characters"
       data-val-length-min="5" />
haim770
  • 48,394
  • 7
  • 105
  • 133