How can we enable data annotation validation on client side in MVC?

 This can be done in two steps.

Step 1:

 In this step we will add necessary Jquery files.

<script src="<%= Url.Content("~/Scripts/jquery-1.5.1.js") %>" type="text/javascript"></script>
<script src="<%= Url.Content("~/Scripts/jquery.validate.js") %>" type="text/javascript"></script>
<script src="<%= Url.Content("~/Scripts/jquery.validate.unobtrusive.js") %>" type="text/javascript"></script> 


Step -2 :

  In this step to call the EnableClientValidation method.

<% Html.EnableClientValidation(); %>


After completing these two steps , you can see the validation message.

Comments

Post a Comment

Popular posts from this blog

Unable to load one or more breakpoints in Visual studio.

The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.

The transaction is aborted or Failure while attempting to promote transaction.